Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Populate a dropdown list with function

Avatar

Former Community Member
I've just recently started using LiveCycle Designer (7.0) and learning JavaScript. I am learning a lot perusing this forum but picking things up piecemeal. I can't figure this out.



I have multiple subform instances with the same objects. One of those objects is a drop-down list. When the form is loaded, I want to assign the same list items to each drop-down on each subform using a function. For instance, this function is the script object Enrollment.SelectedPayers.#variables[0].#script[0]:



function fillList(myList)

{ myList.clearItems()

myList.addItems("Name1","ID1")

myList.addItems("Name2","ID2")

myList.addItems("Name3","ID3")

}



I want to fill Enrollment.SelectedPayers.Payer[*].PayName by calling this function.



Questions:

Where should I call the function so the lists will be filled when the document loads?

How do I call the function so it updates the drop-down? Using direct reference or variable?



This, of course, is a very simplified version of what I'm actually doing. I would appreciate any examples you can provide. I do know how to iterate through the Payer subforms.
3 Replies

Avatar

Former Community Member
Hi,



I assume,
PayName is a subform within all the
Payer subforms. (?)

Then... the following code-fragment should work, if put in the initialize-event of your form.






var arrPayers = xfa.resolveNodes("Enrollment.SelectedPayers.Payer[*]");

for(i in arrPayers)

    myScriptingObj.fillList(i.PayName);





Notice, that you must replace
myScriptingObj with the name of the scripting object, where
fillList(obj) is located in.



Regards,

Steve

Avatar

Former Community Member
Thanks, but this doesn't work either. The dropdowns aren't populated. What am I missing? Here's what I have:



Enrollment::initialize

var arrPayers = xfa.resolveNodes("Enrollment.SelectedPayers.Payer[*]");

for(i in arrPayers)

Enrollment.#variables[0].MyFunctions.fillList(i.PayName);



Enrollment.#variables[0].MyFunctions

function fillList(oPayer)

{ oPayer.clearItems()

oPayer.addItem("ACORDIA","45")

oPayer.addItem("BLUE CROSS","1") }



PayName is the dropdown list within each Payer subform.



Laura

Avatar

Former Community Member
Well, I've made some progress. I'm learning how to use the JavaScript debugger. My first problem was in the way I called the function. I'm still learning the naming conventions and hierarchy. So now the code is:



for(i in arrPayers)

MyFunctions.fillList(i.PayName);



Now the error is in the function - TypeError: oPayer has no properties. So why isn't it recognizing oPayer as the dropdown list object it should be?