- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2017 06:35 AM
Hi All,
We are doing Service Now integration with Remedyforce and SessionId generated from RestMassage with XML response.
We are tried to parse the Rest XML response in Business Rule but unable to parse data.
i am using below code
try {
var r = new sn_ws.RESTMessageV2('Remedyforce SessionID', 'Post');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.addInfoMessage(response.getBody());
gs.addInfoMessage(httpStatus);
//We have tried both formats but its not working for us
/*var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(ResponseBody);
var sessionId = xmlDoc.getNodeText("//sessionId");*/
var xmlDoc = new XMLDocument2(responseBody);
gs.addInfoMessage(xmlDoc.getNodeText("//sessionId"));
var sessionId1 = xmlDoc.getNodeText("/loginResponse/result/sessionId");
gs.addInfoMessage(sessionId1);
}
catch(ex) {
var message = ex.getMessage();
}
//Above code gives the below result:
response.getBody() give plain text without tag instead of XML response in Business Rule.
How to get XML response in Business Rule?
Thanks,
Jitendra Sharma
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2017 11:59 PM
Hi Jitu,
Please have a look at below code...
var s = '<?xml version="1.0" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:inc=\"http://www.service-now.com/incident\"><soapenv:Body><loginResponse><result><sessionId>12364</sessionId></result></loginResponse></soapenv:Body></soapenv:Envelope>';
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(s);
var node = xmlDoc.getNodeText('//sessionId');
gs.print(node)
Replace 's' 'with your responseBody
Please let me know if it works..
Regards,
Jobby EK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2017 11:59 PM
Hi Jitu,
Please have a look at below code...
var s = '<?xml version="1.0" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:inc=\"http://www.service-now.com/incident\"><soapenv:Body><loginResponse><result><sessionId>12364</sessionId></result></loginResponse></soapenv:Body></soapenv:Envelope>';
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(s);
var node = xmlDoc.getNodeText('//sessionId');
gs.print(node)
Replace 's' 'with your responseBody
Please let me know if it works..
Regards,
Jobby EK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2017 12:55 AM
Hi Jitu,
Are you using your xml parsing script in scoped app or global application?
Can you share the xml here so that I can check on parsing that.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2017 02:35 AM
Hi Jitu,
Any update on this?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2018 01:22 AM
Hi Jitu,
Any update on this?
Can you mark answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader