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

Get rawvalue(index) from Listbox using FormattedValue

Avatar

Former Community Member

I have two dropdowns with two different sets of data. one with country and another with profession.

I have a listbox with the all the possible country/profession combined as a formattedvalue. how can I get the rawvalue/index using the formattedvalue from the two fields above.

I will pick a specific country and profession and then I need to get the index of that combo in the listbox.

Any help would be appreciated.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I resolved my issues. here is the code I developed to get the job done. it could be simplified a little further but it worked well.

I put it in the enter action.

var checkValue = [dropdown1].rawValue + [dropdown2].formattedValue + ", "

var oArr = checkValue.split(", ");

var oList = xfa.resolveNode([listbox with the index and concat values].somExpression);

var oListIndex;

while (oArr.length!=0){

oListIndex = oList.boundItem(oArr.pop());

oList.setItemState(oListIndex-0,1);

}

NOTE: You can add if statement to make it run only if those fields have values right before the while statement.

View solution in original post

6 Replies

Avatar

Level 8

If I understand the request correctly, you want to get the values from the two dropdown lists and combine them to set the value in the list box.  To do that the following script should suffice.  You probably want to add some error handling but this should get you started

var d1 = DropDownList1.formattedValue

d1 = d1.concat(DropDownList2.formattedValue)

xfa.host.messageBox(d1)

ListBox1.rawValue = d1

Avatar

Former Community Member

TundraSteve,

Not exactly, my main issue is to find the index value of the specific formattedvalue in the listbox. here is an example which hopefully will better explain:

DD1 - US, China, etc.

DD2 - Job1, Job2, etc.

Listbox -

1 | USJob1

2 | USJob2

3 | ChinaJob1

4 | ChinaJob2

By using the top two dropdowns, can I get the index value? so if someone picks China and Job1, I can get index 3? I know how to aggregate the formattedvalues.

Avatar

Level 8

Why do you want the index value?  What are you going to do with it?  You could set the selection as I mentioned above and then use ListBox1.selectedIndex to get the index or if you don't want to set the value in the listbox just loop through the listbox items and compare to the combined dropdown values

Avatar

Former Community Member

long story...the form is connected to a database but it is sent to a external contact where we want to validate real-time prices. so, we are pushing the data into multiple listboxs because they wouldnt have the db connection. after i get the index, i will know which value to use in another listbox (which is defined depending on another dropdown selection)

Can you help me understand how you would compare the combined dropdown? my one other issue is they could manually type a country and if we do not have the rates, it will not validate the pricing. This is needed because we do business globally.

Avatar

Correct answer by
Former Community Member

I resolved my issues. here is the code I developed to get the job done. it could be simplified a little further but it worked well.

I put it in the enter action.

var checkValue = [dropdown1].rawValue + [dropdown2].formattedValue + ", "

var oArr = checkValue.split(", ");

var oList = xfa.resolveNode([listbox with the index and concat values].somExpression);

var oListIndex;

while (oArr.length!=0){

oListIndex = oList.boundItem(oArr.pop());

oList.setItemState(oListIndex-0,1);

}

NOTE: You can add if statement to make it run only if those fields have values right before the while statement.

Avatar

Former Community Member

additionally, the above code was used to figure out what the index was for a specific formattedvalue in a listbox. here is the code which I used to use it to look up a value in another listbox.

check = xfa.resolveNode([listbox 2 which has the value you need).getDisplayItem([listbox1 where you selected the formattedvalue in the code above]);

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] ----