Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Dynamically Populating Drop Down Lists

Avatar

Level 1

Hi,

I am trying to dynamically populate a drop down list on a form based on a selection in another drop down list. I have read the help file "To dynamically populate a second field after populating the first" which goes through an example, however I cannot get this example to work for me.

I know that the best way to do it is to create an xml file and connect the form to this file. I am new to programming in xml but have had some experience in other forms. The code that I have (from the help page) looks like this;

<?xml version="1.0" encoding="UTF-8"?>

<MyData>
   <country/>
   <countries>
      <item uiname="United States" token="US"/>
      <item uiname="Vietnam" token="SRV"/>
   </countries>
   <state/>
   <US>
      <item>California</item>
      <item>New York</item>
      <item>Texas</item>
   </US>
   <SRV>
      <item>An Giang</item>
      <item>Bac Giang</item>
      <item>Bac Kan</item>
   </SRV>
</MyData>

I have then followed the instructions on the page, and am unable to populate either field on my form. Perhaps there is something wrong with my code? Or any other suggestions would be greatly appreciated! 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Are you merging the data file into the form? If you are using Preview you have to point to the data file where the data to be merged resides. This can be found in the File/Form Properties/Preview section. If you are not using preview then you will still have to get the data file. You can use the Forms/Manage Form Data/Import Data menu item in Acrobat or Reader.

If that does not help then email the form and that data file to LiveCycle8@gmail.com and I will have a look.

Paul

View solution in original post

4 Replies

Avatar

Correct answer by
Former Community Member

Are you merging the data file into the form? If you are using Preview you have to point to the data file where the data to be merged resides. This can be found in the File/Form Properties/Preview section. If you are not using preview then you will still have to get the data file. You can use the Forms/Manage Form Data/Import Data menu item in Acrobat or Reader.

If that does not help then email the form and that data file to LiveCycle8@gmail.com and I will have a look.

Paul

Avatar

Level 1

Ahhh,

Thats what I was missing. I have got it working now.

Thanks Paul!

Avatar

Level 1

Hi Paul,

I have another question,

I would now like to populate a third drop down menu based on the selection in the second one, however my code is going wrong somewhere as now when I put in the first 2 drop down lists, nothing appears in the second one. ie, the first drop down list I link to countries, and the second to state, as I did with the previous file, but now, when I preview it, I can choose a country, but nothing comes up in state. When I set the first drop down box to countries, I have to specify that I want it to show the uiname, but I can't do that with the second one when I select state using the XML file below, nothing is shown. Where am I going wrong?

<MyData>
   <Country/>
   <countries>
      <item uiname="United States" token="US"/>
      <item uiname="Vietnam" token="SRV"/>
   </countries>  
   <state/>
   <US>
      <item uiname="California" token="CA"/>     
      <item uiname="New York" token="NY"/>   
      <item uiname="Texas" token="TEX"/>
   </US>
   <SRV>
      <item uiname="An Giang" token="AG"/>
      <item uiname="Ban Giang" token="BG"/>
      <item uiname="Bac Kan" token="BK"/>
   </SRV>
   <time/>
   <CA>
      <item>6</item>
      <item>7</item>
   </CA>
   <NY>
      <item>5</item>
      <item>4</item>
   </NY>
   <TEX>
      <item>3</item>
      <item>8</item>
   </TEX>
   <AG>
      <item>2</item>
   </AG>
   <BG>
      <item>1</item>
   </BG>
   <BK>
      <item>9</item>
   </BK>
</MyData>

Thank you for your help!

Avatar

Former Community Member

You may want to try adding the command xfa.layout.relayout() to the end of your script. This causes the form to refresh. Without seeing the form it is hard to say but refreshing the lists after you change them is always a good idea.

Paul

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----