Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Null value while parsing xml

dvelloriy
Kilo Sage

Hi Community,

I have developed an outbound integration in ServiceNow. For failed transactions, i have created a retry policy and a business rule to create an incident. However while parsing xml, it is giving null value.

I want to parse the below parameter:

find_real_file.png\

In my BR, i am using:

var payld = current.input_queue.payload;
var snowgrp = gs.getXMLText(payld,"//http_status_code");
gs.log("Value of snowgrp is"+snowgrp);

 

Logs:

find_real_file.png

 

Any help on this would be appreciated.

1 ACCEPTED SOLUTION

Well you could either use

var xmlDoc = new XMLDocument(current.input_queue.payload,true);
inc.work_notes = "The  incident failed to send notification to end user. Error code is " + xmlDoc.getAttribute("//parameter[@name=\"http_status_code\"]","value");

or

var xmlDoc = new XMLDocument(current.input_queue.payload,true);
var errorCode = xmlDoc.getAttribute("//parameter[@name=\"http_status_code\"]","value");
inc.work_notes = "The  incident failed to send notification to end user. Error code is " + errorCode;

Just depends if you want to create a variable for it or just use the parsing directly

View solution in original post

19 REPLIES 19

Abhinay Erra
Giga Sage

Use this 

 

var xmldoc = new XMLDocument(current.input_queue.payload);
var str = xmldoc.getNodeText("//http_status_code");
gs.log(str);
 

Hi Abhinay, Still getting null value.

Try this

 

gs.log((/<parameter name="http_status_code" value="(\w*)"\/>/g).exec(current.input_queue.payload)[1]);

So you mean, shall i replace gs.log(str); with 

gs.log((/<parameter name="http_status_code" value="(\w*)"\/>/g).exec(current.input_queue.payload)[1]);

?