Skip navigation
Currently Being Moderated

Problem accessing XML values from webservice call to SAP. Javascript, LiveCycle ES8.2

May 11, 2010 10:05 PM

Guys

I am finding difficulty accessing the values of XML data supplied from a webservice call (to a SAP ABAP webservice).  I am using LiveCycle 8.2 and javascript.  The web service itself uses Document style binding in the WSDL.  My javascript specifies XML binding (though I have also tried Message and JS style binding.)

 

When I execute the webservice call, I can use SOAP.wireDump = true; to see the contents of the XML returned (see a brief excerpt below):

 

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header></soap-env:Header>
<soap-env:Body><n0:ZFMWSResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">

 

<Contents>
     <Item>
     <Name>String</Name>
     </Item>
</Contents>

 

<ReturnContents>

     <Item>
     <Name>String1</Name>
     <Item>

 

     <Item>
     <Name>String2</Name>
     </Item>
</ReturnContent>

etc etc

 

This XML is stored within a variable called "result".

 

Now it gets interesting.  I can easily access the value of the <Contents><Item><Name> </Name> string (i.e. String1) using the following javascript syntax:

 

console.println(result.Contents.Item.Name);

This syntax (i.e. result.Contents.Item.Name) also works when I display the result in a form text field.

 

This is slightly curious as I would have anticipated that .value or .soapValue would be required to access the value, but no, simply using the syntax above retrieves the value.

 

Why this works I am unsure.  However.  When there is more than one repeating value in the XML i.e. there are two <Item> instances in <ReturnContents>, I cannot find a valid syntax to access any of their values.

 

For example,

 

console.println(result.ReturnContents.Item[0].Name); does not work!

 

I do not seem to be able to find any syntax that accesses the value of <Item> when there are multiple instances of Item in the XML.

 

I have tried many things including trying to parse the contents or result into XML i.e.:

var myXML = XMLData.parse(result, false);
var a = XMLData.applyXPath(result, "//item");
a.saveXML('pretty');

 

If this worked, I could then easily navigate through to the values I need.

 

etc etc.

 

However this always causes an error.  When this script runs the contents of 'result' (which is storing the XML returned from the webservice) always appear to be empty.  The error is: Xml parsing error: no element found (error code 3).

 

Does anyone have any ideas?  The main problem seems to be that I cannot properly access the properties of the 'result' variable which holds the XML returned from the web service.

 

The only property of this 'result' vairable which returns something other than null or empty is:

 

result.ReturnContents.length;

 

This then returns the number of <Items> under the <ReturnContents> node.  However, result.ReturnContents.value (or any similar syntax) always returns empty.

 

What is the syntax to access multiple <Items> under <ReturnContents>?


Any thoughts would be very much appreciated!
Thanks
Roxy

 
Replies
  • Currently Being Moderated
    May 12, 2010 9:28 AM   in reply to RoxyOzGirl

    You are using two different technologies to look at the result of your web service.

    The SOAP.wiredump is the Acroform way of looking at soap results. It creates a results object for and hence you can navigate down the tree (without a value param) to get what you are after.

     

    When you start trying to manipulate the XML you are using XFA commands. Generally the two do not mix.

     

    As a solution to your issue I woudl load the wsdl for your service in the Data Connection view and if you are getting a single XML stream back then assign the output to a multiline field. Then you coudl load the xml into the data dom and now those commands that you have been using will work.

     

    There have been a couple of posts about loading returned XML into the Dom so you might want to search on those as well.

     

    Hope that helps

    Paul

     
    |
    Mark as:
  • Currently Being Moderated
    May 13, 2010 5:13 AM   in reply to RoxyOzGirl

    You are still mixing methods.

     

    There is nothing wrong with using the AcroForm method...but I prefer the XFA way (if it suits yoru web service).

     

    In Designer under the Data Connection you can choose a wsdl to connect to. This will imspect the wsdl and will expose any INputs and outputs in a tree structure in that view. You can then drag and drop the inputs and outputs of the web service onto the appropriate fields on your form this setting up bindings between the two. There is also a button definition provided in the data view. You can drag that onto the form and when you press it the web service executes and the bindings are run and your fields are populated.

     

    Make sense?

     

    Paul

     
    |
    Mark as:
  • Currently Being Moderated
    May 14, 2010 4:47 AM   in reply to RoxyOzGirl

    Just as a point of interest that technique does support a secure web service call.A dialog will appear allowing you to enter the credentials when you execute the service; however you will not be able to put the credentials in the call programmatically (I then question why there is security on the WS at all if you are going to hardcode a program to enter the credentials).

     

    Paul

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 18, 2011 9:06 AM   in reply to pguerett

    Hello RoxyOzGirl,

     

    I have the same problem ... were you able to access the returned data?

     

    I would like to do the acces programmatically but I found some difficulties and my meantime solution is to use the postExecute event of the button in order to manage the returned data from the WS. Obviously with this solution I need to define the Data Connection for the WS, which I would like to avoid and in the case that authentication is needed it won't work.

     

    in the XML Source add the event to the button

    <

    event activity="postExecute" ref="xfa.connectionSet.<ConnectionName>" name="event__postExecute">

     

    the event postExecute will appear in the JavaScript editor for "Events with Scripts" where you have to write your code to acces to the returned WS data

     

    items

    = xfa.datasets.connectionData.<ConnectionName>.Body.<WS_RESPONSE>.<TABL E>.<TABLE_LINE>.all;

    for (i = 0; i < items.length; i++) {

         instance

    = <RESULT_FORM>.<RESULT_TAB>._<RESULT_TAB_LINE>.addInstance(1);

         instance.<FIELD>.rawValue = items.<TABLE_LINE>(i).<FIELD>.value;

    }

     

    In any case, I am not happy with this solution, as I would like do it 100% programmatically.

     

    Kind regards,

    G.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points