JavaScript

Features ›› Reference Data ›› getAffinityList ›› Sample Code ››
Parent Previous Next

Get Affinity List


We need to import useful data from these 4 sources, and to load 4 different types of functions below.









There is a function called "loadReferenceData". It contains 8 different types of functions:



The "loadReferenceData" function is to ensure functions are executed sequentially. Without it, these 8 functions above are not be able to execute.








We will create a function called: getAffinityListName.

AffinityListID is the data that we are going to match.

Then, we will use for loop to loop AffinityLists1, and use an empty variable product to store all the looped AffinityLists1(Every time to loop AffinityLists1, there will be different value coming out.).

If AffinityID in the variable AffinityList can match AffinityListID, then it will return the Affinity Level1 from the variable AffinityList.

Else, if AffinityID in the variable AffinityList cannot match AffinityListID, then it will return undefined.


We will repeat the steps above to create a second function called getAffinityListName2 to return Affinity Level2.








We will create an empty variable AffinityLists1(used in function getAffinityListName(AffinityListID)) and a function "loadAffinityList".

Then, we will set request parameters by creating a variable headerobj:

The header contains:



Then set up http request and http event handlers.

If globalErrorID is equal to "010000"(means no error),

AffinityLists1 will contain all the data in responseObj.Content.ServiceResponse.AffinityList.Affinity.

Else, the system will come out an alert message: "Error retrieving document type list."

Once time is out, the system will come out an alert message: "Timeout retrieving document type list."


Likewise, we will repeat the steps above to get Affinity Level2.




onreadystatechange


This code required data variable onreadystatechange from Jsp, please refer to onreadystatechange above.


xmlHttp


This code required data variable xmlHttp from Jsp, please refer to xmlHttp above.


ApiURL


This code required data variable ApiURL from Jsp, please refer to ApiURL above.


ontimeout


This code required data variable ontimeout from Jsp, please refer to ontimeout above.




How can we test the getAffinityListName and getAffinityListName2 function?

In order to test the functions, we can use getCustomerAffinities.html to test it.

Created with the Personal Edition of HelpNDoc: Easy CHM and documentation editor