Retrieve value form SOAP XML Response

sam352120
Kilo Guru

Dear All,

We are trying to fetch some value from the soap messageresponse (xml) which will be captured in a variable in the workflow run script ,but not able to succeed to do that. Please find the xml response below for reference.

We would like to fetch either the value of the code or the message for our requirement purpose.

Response Body:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:GetUserIDResponse xmlns:ns2="http://www.asentinel.com/asentinelws/schemas/invord"><ns2:result><ns2:code>-1</ns2:code><ns2:message>Could not find user with username test000@xxx.com.</ns2:message></ns2:result></ns2:GetUserIDResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

Any assistance appreciated.

Thanks,

Sambit

2 REPLIES 2

Boyan1
Kilo Sage

Hello, 

When you receive the response, please try

var xmlDoc = new XMLDocument(response.getBody());

var code= xmlDoc.getNodeText("<add element here>");

 

Then you can pass the value as needed.

Best regards,

Boyan

Hi Boyan,

Thanks for your response.We tried to execute the above code as mentioned.

 

Code used:

------------

var response = s.execute();
var responseBody = response.getBody();
var status = response.getStatusCode();

 

gs.log(" Response Body:" + responseBody);
var xmlDoc = new XMLDocument(response.getBody());

 

var result= xmlDoc.getNodeText('message');
var res=xmlDoc.getNodeText('code');

gs.log('Code'+ res);
gs.log('Msg'+ result);

 -------------

Tag Line:<>

var response = s.execute();
var responseBody = response.getBody();
var status = response.getStatusCode();

 

gs.log(" Response Body:" + responseBody);
var xmlDoc = new XMLDocument(response.getBody());

 

var result= xmlDoc.getNodeText('<message>');
var res=xmlDoc.getNodeText('<code>');

gs.log('Code'+ res);
gs.log('Msg'+ result);

 

 

Following response received:

--------------------------------

find_real_file.png

 

Can you suggest..

 

Thanks,

Sambit