Jun 03 2008

Dynamically populate dropdown lists using webservices

Published by Peter Schellemans at 11:53 am under LiveCycle Designer

Disease:

How to dynamically populate a dropdown list in a pdf form with results from a webservice? Typically one can accomplish this by using lots of hidden fields to capture the webservice results, and write multiple lines of Javascript code to populate the dropdown list based on the values of these hidden fields. There is however a much shorter way!

Prescription:

LiveCycle Designer 8 offers a nice new functionality.

1) Select the dropdown list and go to the Object Palette.

2) There select the right most icon.

3) Since version 8 one can choose “Show Dynamic Properties”. The result of this is that “Caption” and “List Items” become links instead of just labels.

4) Choose “List Items” and bind the dropdown list items to the return value of the webservice (through the webservice dataconnection).

This is it.

One can go a step further. Suppose you want to select a value from this dropdown list, which needs to be used as input for a second webservice, which needs to populate on its turn a second dropdown list. The same applies for the second dropdown list.

1) Bind it dynamically to the result of the second webservice.

2) Make sure however that in this case you use execute(0) when writing the Javascript code to call the second webservice, and not execute(1). Execute(0) will make sure that the DOM is not remerged (with the risk that the first dropdown list gets empty again)

Tip to stay healthy:

Start questioning your code when you see your lines of code and your amount of hidden fields growing just to accomplish an easy population of lists. Chances are big that Designer offers a functionality to do this on the fly.

3 responses so far

3 Responses to “Dynamically populate dropdown lists using webservices”

  1. MuratKuruon 19 Nov 2008 at 10:52 am

    Hi,
    I have 2 drop down list on my form (LC designer 8.2). Both of them is connected to Access databases. (Countries and cities.) I want to select country on first drop down list then I want to show just selected country’s cities on the second drop down list.
    What I did till now is;

    I wrote this on first drop down list’s “change” event

    var sCategoryId = country.rawValue
    var oDataConn = Ref(xfa.sourceSet.DataConnectionCOUNTRY.clone(1))
    oDataConn.#command.query.commandType = “text”
    oDataConn.#command.query.select = concat(”SELECT * FROM COUNTRY WHERE IL_ID = “, var sCategoryId)
    oDataConn.open()

    I don’t have any message but i doesn’t work? Do you have any idea?

    Thank in advance..

  2. MuratKuruon 26 Nov 2008 at 2:34 pm

    Hi all,

    We have solved the problem that I mention above.

    You can find detailed information (example) about “dynamically populated dependent drop down lists using OLDB connection” from the link below.

    http://blog.vukuf.com/2008/11/populating-drop-down-list-from-database.html

    Thank you Peter (from Adobe Systems Benelux BV) for your cooperation and help

  3. shopieon 19 Feb 2009 at 8:05 am

    Hi Peter,

    You said that, to dynamically populate a dropdown list in a pdf form with results from a webservice we need to create lots of hidden fields to capture the webservice results, and write multiple lines of Javascript code to populate the dropdown list based on the values of these hidden fields. How to do this ? I mean how to assign hidden field values to drop down list ?

    Can we change the field label/name dynamically ?

Trackback URI | Comments RSS

Leave a Reply