The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Parsing through XML document

cnharris1
Kilo Sage

Good morning,

I'm grabbing an XML document through a rest call and that part is working fine.

But when I get the xml document back, I need to parse through the document and grab the customer information, such as their first and last name, phone number, and email. The problem is that there are multiple contacts in the document but the only one that I need to grab is where the contact type = MAIN.  

 

I'm assuming that I would need to loop through all of the contacts to grab the one that I need, which is the MAIN contact.

Would someone be able to assist me in writing the code to grab that information?

Best regards,

 

cnharris1

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi

to keep it simple I recommend converting the XML payload into JSON. That way it is easier to parse and loop through.

 

See https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0957116 

View solution in original post

5 REPLIES 5

Hi Sandeep,

Thanks for that link! It was very insightful because I'm going to need that for future projects that I'll be working on. Due to the time constraints though, I decided to convert my xml file to JSON and loop through it to get the contact information I needed.

 

Thanks again,

 

cnharris1