Highlighted

Populating Drop Down List Items via Web Service

Avatar

Guest

20-08-2008

We have version 8.2 of LiveCycle and are trying to populate a drop down list of values via a web service. We have successfully build a web service in WorkBench that will query a database for unique values in a particular Oracle database table. Those values are required to populate the drop down list in the form. We're having a problem figuring out the approach and best practice.



The web service was created by using the "Query Multiple to XML" activity. The properties tab of the activity require the following:



b Root Element Name



b Repeating element Name



b Column Name Mappings



We have used "form1" as the root element name and "test" as the repeating element name because those are the xml structure of the PDF form in question. We then mapped the column name from our SQL query to the element name "section" in our column name mappings. Unfortunately, the resulting xml has a repeating element of "test", although that element only appears once in the PDF xml. If we leave the root element name and repeating element names blank, the resulting xml defaults to "root" and "element". Not sure what we are supposed to do in this case?



Then, in the form that we want to call this web service, we add a "data connection" using the WSDL created by our new process. When we create the data connection, I then see the invoke request and invoke response, as well as invoke button in the data view. We dragged the button onto the form and then I enabled dynamic labels in the form. For the target drop down list, I clicked on "List Items" and selected the data connections, then configured the binding. For the binding, I selected invokeResponse->outputXML->document. The problem is that the entire output xml is then entered in the drop down. It does not parse the XML output to populate the drop down.



Questions:

1) How do we do parse the XML for the drop downs?

2) Do we need to create more output variables in our web service that parses the XML into some sort of list format?

3) What are the best practices for populating a drop down list in version 8.2?



Thanks

Replies

Highlighted

Jasmin_Charbonn

21-08-2008

1) How do we do parse the XML for the drop downs?<br /><br />You can't bind directly to the xml returned from a web service. You'll get (like in your case) the whole xml. This is a know limitation and the next version might address that.<br /><br />For the time being, what we do is bind the xml to a hidden field instead then load the content (xml) in the data DOM of the form so we can use script to access the data. Then loop though the data structure and populate the dropdown. Here a snippet of the code:<br /><br />//Load the data in the data DOM<br />//HellowWorldResult is the hidden field that contains the result of //the web service<br />xfa.data.loadXML(HelloWorldResult.rawValue);<br /><br />//TempData is created because of the data structure returned by the //web service. In you case you might need to use //xfa.datasets.data.test.nodes (the root node is getting dropped so //no form1)<br />var objList = xfa.datasets.data.TempData.nodes;<br /><br />for(i=0;i<objList.length;i++){<br /> DropDownList1.addItem(objList.item(i).value);<br />}<br /><br />2) Do we need to create more output variables in our web service that parses the XML into some sort of list format?<br /><br />You'll have the same problem with any complex structures.<br /><br />3) What are the best practices for populating a drop down list in version 8.2?<br /><br />See #1<br /><br />Jasmin
Highlighted

Avatar

Guest

27-08-2008

Hi Jasmin,<br /><br />We created a web service to return the values necessary for the drop down list. I bound the hidden field to the web service invoke response document and can see the xml data in the field (when not in hidden mode). The problem is that I cannot get the data to populate the drop down correctly. In the next line of code, should I insert "datasets" between xfa and data? I tried that, but it still did not work.<br />xfa.data.loadXML(HelloWorldResult.rawValue); <br /><br />I then added the next line here:<br />var objList = xfa.datasets.data.test.nodes; <br /><br />for(i=0;i<objList.length;i++){ DropDownList1.addItem(objList.item(i).value); } <br /><br />I'm getting nothing inside my drop down list. I see the xml in the hidden (not so hidden) field, but the nodes are not transferring so well to my list. any thoughts?
Highlighted

Avatar

Guest

27-08-2008

Hi Eric,

I believe there is another more straight forward way by configuring your dropdownlist to be dynamically bound to a webservice.

1. On your designer with your form opened, click your dropdown field, go to Tool>Options and select data binding, and check the "Show Dynamic Properties" and "Use Custom Label Color" and click ok.

2. Click on your drop down field again, and you should see the color is highlighted now for "List Items:" on object "Field" properties.

3. Click on the text "List Items:", and it will show its dynamic property.

4. Select the data connection for the webservice call.

5. The items should point to your repeating element of the return XML. And Item text and item value to the sub-elements within the repeating element.

E.g. 12

Hope that helps.

Kendy
Highlighted

parth_pandya

27-08-2008

Hi Guys,<br /><br />I would like to clarify few things here. <br /><br />We are trying to solve more than one problem here so things are little blur and thus its not working for Eric.<br /><br />My observations:<br /><br />1. Orchestration which is exposed as WebService in livecycle does not expose the xml variable in 'schema aware manner'. So we see outputXML->document in the data binding tab in designer. And thus dynamic properties aren't working without any javascript code.<br />2. The dynamic properties approach (followed by Eric and posted by Kendy) works perfectly (without needing any line of code) with webservices which describe xml structure in web service response. This does not happen with livecycle webservice so little bit of coding is needed. <br />Also note that the dynamic properties will also work beautifully if you are using form data to populate the combo which Jasmin suggested by writing the web service response in data DOM. But it's not so good design as there is a chance of loosing form specific data if you write web service response xml on top of form data dom.<br />3. For some reason script from Jasmin didn't work for me...<br /><br />So i came up with a generic script which is a replacement of Jasmin's suggestion.<br /><br />In Below snippet i'm assuming that returning xml looks like this<br /><form1><br /> <test><br /> <section>1</section><br /> </test><br /> <test><br /> <section>2</section><br /> </test><br /> <test><br /> <section>3</section><br /> </test><br /></form1><br /><br />Script to populate dropdown with sction values should be:<br /><br />var tree = XMLData.parse(HelloWorldResult.rawValue, false);<br />var mynodes = XMLData.applyXPath(tree,"//form1/test/section");<br />if (mynodes == null) {<br /> // no data<br />} else if (mynodes.length == null) {<br /> // not an array, just a single value<br /> DropDownList1.addItem(mynodes.value);<br />} else {<br /> for (var i = 0; i < mynodes.length; i++) {<br /> DropDownList1.addItem (mynodes.item(i).value);<br /> }<br />}<br /><br />I've used XMLData object to covert string into xml document.<br />Then i use xPath expression to get desired xml element values.<br />And simply call addItem(value) on dropdown field to add values.<br /><br />Cheers,<br />Parth Pandya<br />http://www.avoka.com
Highlighted

Avatar

Guest

28-08-2008

Hi Parth,

It worked beautifully!

As for Jasmin's appoach, it did not work. In the web service that returns the XML, I used an xsl transform activity to modify the xml, but it still did not work. The query multiple to xml returns


1



2



3



It would work, but I would only get section1 in the drp down, not the rest. I tried manually entering xml that looks like below and it worked perfectly

I applied xsl transform and changed the xml output to:


1

2

3



This caused a crash in the PDF preview and it would not work.

Parth's code above works, so I'll stick with that for now. Thanks Parth!
Highlighted

Avatar

Guest

10-09-2008

Is it possible access the XML placed into the XML Source of the PDF?


John
Kevin
Sara



Because when type xfa. I can see FormData as a selection.

How can I hardcode the XML data in the XML Source and then have a dropdown list prepopulate on load?

Thanks,

Kris
Highlighted

pguerett

10-09-2008

You can bind a node in the data that contains the data that you want in the dropdown but you would have to merge the data file each time you render the form. The data dom is not part of the template that you create but a separate XML file.
Highlighted

Avatar

Guest

10-09-2008

I thought I could make this easy for me if I just hardcoded the data in the XMl Source of the PDF Form.



I created a DataConnection to bring in my XSD but I do not know where to bring in the reference data.



This item is taking up way too much time. lol



What would you suggest?



Regards,



Kris