Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Populating Drop Down List Items via Web Service

Avatar

Former Community Member
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
14 Replies

Avatar

Level 10
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

Avatar

Former Community Member
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?

Avatar

Former Community Member
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

Avatar

Former Community Member
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

Avatar

Former Community Member
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!

Avatar

Former Community Member
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

Avatar

Former Community Member
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.

Avatar

Former Community Member
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

Avatar

Former Community Member
I moved my XML within the xfa:datasets tags and then the following works.



Combobox.addItem(xfa.datasets.FormData.Manager.nodes.item(0).value);



But the xfa.datasets.FormData.Manager.nodes.length does not count the number of items.



Any suggestions? Also, Am I doing this in a way that will cause me some issues in the future?



I need a pdf form that sits on the client's computer and does not require web services.



Thanks,



Kris

Avatar

Level 10
Put a app.alert(xfa.datasets.data.saveXML()); in your code.



You'll see the structure of the data DOM. That way you can write the right expression.



Jasmin

Avatar

Former Community Member
Any other suggestions on how to get a total number of items?



xfa.datasets.FormData.Manager.nodes.length does not work.



Regards,



Kris

Avatar

Level 10
Can copy the content of app.alert(xfa.datasets.data.saveXML());?



I want you to do that so you can see the structure of the XML. Paste it in here and we'll help.



xfa.datasets.FormData.Manager.nodes.length doesn't make, but in order to help, we need to know the structure of your data.



If you look at my first post on this topic, the format would be somthing like: xfa.datasets.data. then the rest of your structure. Also it'll drop the root node.



So my guess would be that xfa.datasets.data.Manager.nodes.length



Jasmin

Avatar

Former Community Member
Hi Jasmin,<br /><br />I ended up using the saveXML command and most of Parth's code.<br /><br />var xmlData = xfa.datasets.FormData.saveXML();<br />var treeDataName = XMLData.parse(xmlData, false); <br />var mynodesDataName = XMLData.applyXPath(treeDataName ,"//FormData/Manager/Profile/Name"); <br />if (mynodesDataName == null) { <br /> // no data <br />} else if (mynodesDataName.length == null) { <br /> // not an array, just a single value <br /> ManagerName.addItem(mynodesDataName.value,mynodesDataName.value); <br />} else { <br /> for (var i = 0; i < mynodesDataName.length; i++) { ManagerName.addItem(mynodesDataName.item(i).value,mynodesDataName.item(i).value)} }<br /><br />But I cant help thinking since the data is in XML it cant be binded easier..<br /><br />here's the XML<br /><br /><FormData><br /> <Manager><br /> <Profile ID="1"><br /> <Name>Name 1</Name><br /> <Phone>Phone 1</Phone><br /> <Email>Email 1</Email><br /> </Profile><br /> <Profile ID="2"><br /> <Name>Name 2</Name><br /> <Phone>Phone 2</Phone><br /> <Email>Email 2</Email><br /> </Profile><br /> <Profile ID="3"><br /> <Name>Name 3</Name><br /> <Phone>Phone 3</Phone><br /> <Email>Email 3</Email><br /> </Profile><br /> </Manager><br /></FormData><br /><br />I have to run all these for statements (which not happy with) and I think it will slow things down eventually.<br /><br />Do you have an idea how to add TextBoxes, Checkboxes, Etc. via script?<br /><br />Thanks,<br /><br />Kris