- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2014 01:31 PM
I am setting up an integration with Workday.
I am making a soap call from a business rule, in which it returns XML in the response. This response (wd:Get_Workers_Response) contains about 1000 records which I would like to separate out by user (Worker), which will create a new record in our instance per user. When I convert the XML to an object, how do I access that node (if I am asking that correctly)? The node I am trying to access is <wd:Response_Data>. Under that, each worker is <wd:Worker>.
This script doesn't work for me
var s = new SOAPMessage('WorkdayIntegration', 'Get_Workers'); s.setStringParameter('Effective_Through', '2014-09-30T00:00:00'); s.setStringParameter('Effective_From', '2014-09-01T00:00:00'); s.setStringParameter('version', 'v21.0'); s.setStringParameter('Updated_From', '2014-09-01T00:00:00'); s.setStringParameter('type', 'Employee_ID'); s.setStringParameter('Updated_Through', '2014-09-30T00:00:00'); s.setStringParameter('Exclude_Inactive_Workers', 'true'); var response = s.post(true); var xmlHelp = new XMLHelper(response); var obj = xmlHelp.toObject(); JSUtil.logObject(obj, 'The Javascript Object'); var test3 = obj.getNodeText("//*[local-name()='wd:Worker']");
Solved! Go to Solution.
- Labels:
-
Ask the Expert

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2014 04:05 PM
Hi Monroe,
Try something like the following. It basically branches its way down the response tree until it gets to the 'wd:Name_Detail_Data' object which contains properties for first, middle and last name etc. You may need to reformat the tabbing as the syntax highlighter has modified mine.
var obj = xmlHelp.toObject(); // get entire response as object
if(obj){
var env_body = obj['env:Body']; // get object in first tier
if(env_body){
var wd_get_workers_response = env_body['wd:Get_Workers_Response']; // get object from first tier
if(wd_get_workers_response){
var wd_response_data = wd_get_workers_response['wd:Response_Data'];
if(wd_response_data){
var wd_worker_arr = wd_response_data['wd:Worker'];
if(wd_worker_arr){
for(var i=0;i<wd_worker_arr.length;i++){ // this will loop for all instances of the "wd:Worker" element. You may need to modify this to check for non-array though as the structure for a single element would be different
var wd_worker = wd_worker_arr[i]; // get current worker element in array
if(wd_worker){
var worker_data = wd_worker['wd:Worker_Data'];
if(worker_data){
var wd_personal_data = worker_data['wd:Personal_Data'];
if(wd_personal_data){
var wd_name_data = wd_personal_data['wd:Name_Data'];
if(wd_name_data){
var wd_legal_name_data = wd_name_data['wd:Legal_Name_Data'];
if(wd_legal_name_data){
var wd_name_detail_data = wd_legal_name_data['wd:Name_Detail_Data'];
if(wd_name_detail_data){
// get string values from object
var first_name = wd_name_detail_data['wd:First_Name'];
var middle_name = wd_name_detail_data['wd:Middle_Name'];
var last_name = wd_name_detail_data['wd:Last_Name'];
}
}
}
}
}
}
}
}
}
}
}
}
Regards,
Jake

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2014 04:41 AM
Hi Monroe,
I'm glad you figured it out! All the best.
Regards,
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2014 01:31 PM
Hey Jake,
something that I've been playing around with cases of a single worker (which you commented will affect the for loop). I've basically created an if statement to execute if there is a single worker, else execute other code if there is an array of workers. Do you think this is the most efficient way?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2014 03:55 PM
Hi Monroe,
It sounds like you're on the right track. The important thing is to make sure you branch for each possible outcome, including if the worker object is not there (I assume you would discontinue running the script if this happened etc). As long as you've covered all of the possible cases, your integration will work. I usually have each of the "else" blocks report an error code (e.g worker element not found), and then at the end of your sequence check if any errors have been reported (this could be an array that you push error messages to), and if so cancel any record inserts/updates. If your integration is being triggered by a user (e.g via UI Action), you could also return the error message back to the screen via an "addErrorMessage()" etc.
Regards,
Jake