How to return a value from a script step in flow designer.

Sonu Singh
Mega Expert

Hi All,

I need to fetch a value from the response body which i have received it from the SOAP step:

Fig:

find_real_file.png

Can some help me how do i fetch any value from the xml response which i am getting in the responsebody input variable?

 

Thanks,

Ak

1 ACCEPTED SOLUTION

So the problem is the body which is returned from integration.

See formatted XML

find_real_file.png

Below works but it's not good for long time solution.

var response = inputs.response_body.toString();

var xmldoc = new XMLDocument(response);

if(xmldoc.toString().indexOf('name=') > -1){
	var nm1 = (xmldoc.toString().split('name="')[1]);
	var nm2 = (nm1.toString().split('"')[0]);
	outputs.groupname = nm2;
}

View solution in original post

41 REPLIES 41

Hello Ak,

Did you create a variable with group name under output variable section in a script step? If not please create a output variable with name as groupname.

- Pradeep Sharma

Hi @Pradeep Sharma 

Yes, i have created it..

 From the SOAP step i am getting an response like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetSupportSpecialistByLocationResponse xmlns="http://nda.sys.com/">
<GetSupportSpecialistByLocationResult>
&lt;nda-response id="getassociations" status="OK"&gt;
&lt;association&gt;
&lt;people&gt;&lt;/people&gt;
&lt;groups&gt;
&lt;row name="India - Banaglore" email="indbgl@xyz.com" /&gt;
&lt;/groups&gt;
&lt;/association&gt;
&lt;/nda-response&gt;
</GetSupportSpecialistByLocationResult>
</GetSupportSpecialistByLocationResponse>
</soap:Body>
</soap:Envelope>

from this i want to fetch  "India - Banaglore" and pass it to the Outputs.groupname 

 

which i am not able to achieve it.

 

Regards,

Ak

Gaurav Shirsat
Mega Sage

Hi Ak

This Thread might help you.

You can create a JSON object to return multiple values like below

var obj = {};

obj.approver = gr.manager.toString();

obj.approver = gr.user1.toString();

obj.approver = gr.user2.toString();

do refer the below links

https://community.servicenow.com/community?id=community_question&sys_id=1bbde7dbdb4eef8011762183ca96...

https://community.servicenow.com/community?id=community_question&sys_id=b2fe56631bda0010a59033f2cd4b...

Please Mark Correct and Helpful

Thanks and Regards

Gaurav Shirsat

Mike Patel
Tera Sage

try doing instead of gs.print map it to whichever field you want.

var response = inputs.response_body;
var xmldoc = new XMLDocument(response);

var name = xmldoc.getNodeText("//row/@name")

gs.print(name);

Hey @Mike Patel ,

I am not able to map it.

Execution detail: