How to read data in xml tags
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2025 11:42 PM
Hi Team,
Iam getting data from workday integration on workers API. I need to built xpath so it provides us the data.
2024-06-30T00:00:00.000-07:00
2024-05-30T02:21:44.787-07:00
04845bae8a1e42e2ab6da831fef34fb1
Terminate Employee
79e02808d8b31001049bb695db3c0001
38111714
d3ed83aaea99010a390dd7e0ed004c7c
00460131
149748d319111025a59d54cb84843633
48000774
1
0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2025 08:56 AM
convert that to XML to JSON and then parse the JSON
something like this
var xmlString = '<wd:Worker><wd:Worker_Data><wd:Transaction_Log_Corrected_And_Rescinded_Data><wd:Corrected_Or_Rescinded_Transaction_Log_Data><wd:Main_Transaction_Data><wd:Transaction_Log_Data><wd:Is_Rescind_Or_Rescinded>1</wd:Is_Rescind_Or_Rescinded><wd:Transaction_Log_Type_Reference><wd:ID wd:type="Business_Process_Type">Terminate Employee</wd:ID></wd:Transaction_Log_Type_Reference></wd:Transaction_Log_Data></wd:Main_Transaction_Data></wd:Corrected_Or_Rescinded_Transaction_Log_Data></wd:Transaction_Log_Corrected_And_Rescinded_Data></wd:Worker_Data></wd:Worker>';
var jsonObj = gs.xmlToJSON(xmlString); // Converts XML to JSON object
//gs.info(JSON.stringify(jsonObj));
var txnData = jsonObj["wd:Worker"]["wd:Worker_Data"]["wd:Transaction_Log_Corrected_And_Rescinded_Data"]
["wd:Corrected_Or_Rescinded_Transaction_Log_Data"]["wd:Main_Transaction_Data"]["wd:Transaction_Log_Data"];
var isRescind = txnData["wd:Is_Rescind_Or_Rescinded"]; // "1"
var processType = txnData["wd:Transaction_Log_Type_Reference"]["wd:ID"]["content"]; // "Terminate Employee"
// Output (for ServiceNow, use gs.info)
gs.info("Is Rescind: " + isRescind); // Output: Is Rescind: 1
gs.info("Process Type: " + processType); // Output: Process Type: T
Output:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2025 08:15 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2025 10:28 PM
Hi @Ankur Bawiskar ,
But in OOB flow Look up employment data stream we use xpath to read the xml
eg: if i take rehire we hit the workday and use this to get the value for rehire(1/0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2025 10:38 PM
so you are saying there could be multiple objects and each might contain those 2 keys?
you can pass that XML to a script and handle the parsing there
Sorry but I am not knowing your current setup and can only help with what information has been shared.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader