How to Read Values from the XML Payload

vishal065
Tera Expert

Hi,

I am facing to fetch the node value of one the attributes. In my XML Payload, the response is something like:

<domain>europe.abc.com</domain>

Or

<domain>pacific.abc.com</domain>

Or

<domain>americas.abc.com</domain>

Or

<domain>abc.com</domain>

I need to read the first value (before dot) of the attribute <domain>.

So my desired output is: europe Or pacific Or americas Or abc.

I am using below line to get the value but i am getting 'undefined' always

var dom = xmldoc.getNodetext("//domain")

Please advise if anyone knows the solution of it.

Regards
Vishal

1 ACCEPTED SOLUTION

Hi Vishal,



The dom variable should print the value "europe.abc.com" and you wanted to retrieve the value "europe" so as I mentioned earlier in my comment you will have to split using dot



var dom = "europe.abc.com"; // this you are getting as per your comment


var splitValues = dom.split(".");


var firstValue = splitValues[0]; // this prints europe


var secondValue = splitValues[1]; // this prints abc


var thirdValue = splitValues[2]; // this prints com



Can you try and let me know?



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Hi Vishal,



Great that it worked. Could you also mark the answer as helpful and hit like? Thanks in advance.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

How to read XMl payload,

I  have requirement to read data from Payload,but Payload contains data like

<?xml version="1.0" encoding="UTF-8"?><results probe_time="4755" result_code="0"><result><output>Request Status Code:200
Response:&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;applist xmlns:xsi="http&amp;#x3a;&amp;#x2f;&amp;#x2f;www.w3.org&amp;#x2f;2001&amp;#x2f;XMLSchema-instance" app app_id="375" app_name="AIP" policy_updated_date="2019-11-13T11&amp;#x3a;38&amp;#x3a;00-05&amp;#x3a;00"/&gt;

&lt;app app_id="651" app_name="AMP"/&gt;

&lt;app app_id="580819" app_name="AMP-API-File-Registry-Save"/&gt;

&lt;/applist&gt;

</output></result>

Means Inside Xml one more Xml is presented.

Could you help me to how to read this data and store into a table.

 

Thanks,

Uma.

Hi Uma,

Not sure whether it would be a valid response xml within xml from 3rd party application

Regards
Ankur

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

 

Thank you for sharing the solution, I am stuck in a similar kind of issue. 

Scenario:

When i retrieve an update set from dev to test i find that some of the customer updates for their respective retrieved update set are showing wrong. 

I mean that the updated by field on the "sys_update_xml" table and the sys_updated_by field in the payload field (String) are different. 

 

Is there a way to update the updated by field on the sys_update_xml table to be same as the sys_updated_by from the payload?

 

Use Case: using this for automating the change ticket creation with the help of flow designer. There are many update sets which are in complete state in test but for each individual update set there is a respective change ticket automatically created, So if we can either capture the sys_updated_by from the xml payload of the customer update it would solve the issue.

 

Please let me know if you have a solution for it. 

 

Thanks,

pK.

Hi Ankur,

 

Thank you for sharing the solution, I am stuck in a similar kind of issue. 

Scenario:

When i retrieve an update set from dev to test i find that some of the customer updates for their respective retrieved update set are showing wrong. 

I mean that the updated by field on the "sys_update_xml" table and the sys_updated_by field in the payload field (String) are different. 

 

Is there a way to update the updated by field on the sys_update_xml table to be same as the sys_updated_by from the payload?

 

Use Case: using this for automating the change ticket creation with the help of flow designer. There are many update sets which are in complete state in test but for each individual update set there is a respective change ticket automatically created, So if we can either capture the sys_updated_by from the xml payload of the customer update it would solve the issue.

 

Please let me know if you have a solution for it. 

 

Thanks,

pK.