Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Parsing SOAP response programmatically

Avatar

Former Community Member

Good day,

I am connecting to a web service programmatically and with the following code I receive the result below:

var cURL = "http://localhost/soap/myservice.wsdl";

SOAP.wireDump = false;

var service = SOAP.connect(cURL);

var result = service.getReturnsIssuedPersonal("1","2");

Result:

<?xml version="1.0" ?>

- <RHISTORY>

<RETURN>INVALID</RETURN>

<RETURNTYPEREQ>1</RETURNTYPEREQ>

<PERIODREQ>2</PERIODREQ>

<TAXNAMEREQ>4</TAXNAMEREQ>

<SUBISSUE>5</SUBISSUE>

<REFNOREQ>3</REFNOREQ> </RHISTORY>
s

Is there a way that I can parse the result?
Kind regards,
Roy

I

2 Replies

Avatar

Level 10

Hi Roy,

You should be getting a JavaScript object back, add a console.println(result.toSource()); after the call, you should see something like;

({RHISTORY:{RETURN:"INVALID", RETURNTYPEREQ:1, PERIODREQ:2, TAXNAMEREQ:4, SUBISSUE:5, REFNOREQ:3}})

So,

console.println(result.RHISTORY.PERIODREQ);

Will return 2.

One trick if you have a repeating group returned is that the object will contain an array if there is more than 1 otherwise it will just be a nested object, so you might need some code like;

if (response.Messages !== undefined)

{

if (response.Messages.length === undefined)

{

    // only one back;

}

else

{

    if (response.Messages.length > 0)

    {

      for (var i=0; i<response.Messages.length; i++)

      {

         // handle multiple response.Messages[i];

      }

    }

  }

}

Hope that helps

Bruce

Avatar

Former Community Member

the format of the response is determined by the setting of

cResponseStyle

The default is  

SOAPMessageStyle.JS

but it looks like yours is set to

  

SOAPMessageStyle.XML

If you set it to Message, then you will get back JavaScript object literal which is a bit easier to deal with, e.g response.soapValue.