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

@Ankur Bawiskar ,

Had no option,

 

var xmlString = responseBody.toString();
var xmlClean = global.JSUtil.unescapeText(xmlString);
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(xmlClean);

with the above code I tried to convert &it; and &gt; to < and > but it didn't worked. so thought to doing XML Parser step, 

So can you help me out to fetch the values from the below response.

{
"Envelope": {
"Body": {
"name$": "Body",
"GetSupportSpecialistByLocationResponse": {
"name$": "GetSupportSpecialistByLocationResponse",
"GetSupportSpecialistByLocationResult": "&lt;nda-response id=\"getassociations\" status=\"OK\"&gt;&lt;association from_entity_guid=\"123456789\" business_process_role_guid=\"123456789\"&gt;&lt;people&gt;&lt;/people&gt;&lt;groups&gt;&lt;row group_guid=\"123456789\" name=\"IND - BGL\" email=\"indbgl@xyz.com\" ordinal=\"0\" description=\"\" association_guid=\"123456789\"/&gt;&lt;/groups&gt;&lt;/association&gt;&lt;/nda-response&gt;"
}
}
}
}

 

Thanks & Regards,

Ak

 

Hi,

Are you getting this as response?

{"Envelope":{"Body":{"name$":"Body","GetSupportSpecialistByLocationResponse":{"name$":"GetSupportSpecialistByLocationResponse","GetSupportSpecialistByLocationResult":"&lt;nda-response id=\"getassociations\" status=\"OK\"&gt;&lt;association from_entity_guid=\"123456789\" business_process_role_guid=\"123456789\"&gt;&lt;people&gt;&lt;/people&gt;&lt;groups&gt;&lt;row group_guid=\"123456789\" name=\"IND - BGL\" email=\"indbgl@xyz.com\" ordinal=\"0\" description=\"\" association_guid=\"123456789\"/&gt;&lt;/groups&gt;&lt;/association&gt;&lt;/nda-response&gt;"}}}}

Also is this in scoped app since you are using XMLDocument2()

Regards
Ankur

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

@Ankur Bawiskar ,

Yes, i am getting this response from the XML Parser step.

Right now this action is in global, later will make it as scoped.

 

Can you please guide me to fetch those values from the above response.

 

Regards,

Ak

Hi,

what does this print?

var responseBody = inputs.response_body;

Regards
Ankur

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

@Ankur Bawiskar ,

var responseBody = inputs.response_body;

It print the soap response:

<?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>

 

Exact response...