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

Prepopulate a field based on the value of two dropdown list

Avatar

Level 2

Can someone help me? I'm still trying to learn javascript (again)
1508686_pastedImage_0.png

In the image above. Is it possible to prepopulate the Risk Level field based on the value of Likelihood and Severity?
The risk level column need to produce a score from the multiplying the likelihood by the severity selections.


Also, the risk level field bg color needs to change depending on the calculated value (low - green, medium - yellow, high - red)

This is the list for each the dropdown list

Likelihood

  • Very Low (1)
  • Low (2)
  • Medium (3)
  • High (4)
  • Very High (5)

Severity

  • Light (1)
  • Moderate (2)
  • Serious (3)
  • Catastrophic (4)
  • Multi-Catastrophic (5)

Risk Level

  • Low (1-3)
  • Medium (4-9)
  • High (10)

I'm currently using Adobe LiveCycle ES4

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi,

This is a FormCalc solution

Firstly, give the combo items a value.

On the Object > Binding Tab for your dropdownlist, check the box that says Specify Item Values to give a numerical value to each item

1508889_pastedImage_0.png

In my example i have three combos and the Risk Level heading is a textfield, not a text object (it needs to be to be coloured in code).

Note: I have the code triggering on the combo exit event which triggers after you click on an item in the combo box. You will need to add the same code to both the first and second dropdownlists so either performs the calculation.

1508899_pastedImage_3.png

This is my exit code (formCalc):

form1.#subform[0].Table1.Row2.DropDownList2::exit - (FormCalc, client)

//create variables
var ddl1 = DropDownList1.rawValue
var ddl2 = DropDownList2.rawValue

var calc = ddl1 + ddl2 //calculate the dropdownlist values

//if the variable is equal to or greater than 1 and less than 4, select the first item and colour the heading green
if(calc >= 1 and calc < 4)
then
DropDownList3.rawValue = "1"
Table1.Row1.Cell3.fillColor="0,255,0"
endif

//if the variable is greater than 3 and less than 10, select the second item and colour the heading yellow
if(calc > 3 and calc < 10)
then
DropDownList3.rawValue = "2"
Table1.Row1.Cell3.fillColor="255,255,0"
endif

//if the variable is 10, select the third item and colour the heading red
if(calc == 10)
then
DropDownList3.rawValue = "3"
Table1.Row1.Cell3.fillColor="255,0,0"
endif

After making the selection of a second combo, the third combo changes and the title fills with colour.

1508904_pastedImage_5.png

1508905_pastedImage_6.png

1508906_pastedImage_7.png

As there is only 10 options in the calculation, you could also use a switch instead of if expression for this, but this is one case where an if expression is more compact.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 7

Hi,

This is a FormCalc solution

Firstly, give the combo items a value.

On the Object > Binding Tab for your dropdownlist, check the box that says Specify Item Values to give a numerical value to each item

1508889_pastedImage_0.png

In my example i have three combos and the Risk Level heading is a textfield, not a text object (it needs to be to be coloured in code).

Note: I have the code triggering on the combo exit event which triggers after you click on an item in the combo box. You will need to add the same code to both the first and second dropdownlists so either performs the calculation.

1508899_pastedImage_3.png

This is my exit code (formCalc):

form1.#subform[0].Table1.Row2.DropDownList2::exit - (FormCalc, client)

//create variables
var ddl1 = DropDownList1.rawValue
var ddl2 = DropDownList2.rawValue

var calc = ddl1 + ddl2 //calculate the dropdownlist values

//if the variable is equal to or greater than 1 and less than 4, select the first item and colour the heading green
if(calc >= 1 and calc < 4)
then
DropDownList3.rawValue = "1"
Table1.Row1.Cell3.fillColor="0,255,0"
endif

//if the variable is greater than 3 and less than 10, select the second item and colour the heading yellow
if(calc > 3 and calc < 10)
then
DropDownList3.rawValue = "2"
Table1.Row1.Cell3.fillColor="255,255,0"
endif

//if the variable is 10, select the third item and colour the heading red
if(calc == 10)
then
DropDownList3.rawValue = "3"
Table1.Row1.Cell3.fillColor="255,0,0"
endif

After making the selection of a second combo, the third combo changes and the title fills with colour.

1508904_pastedImage_5.png

1508905_pastedImage_6.png

1508906_pastedImage_7.png

As there is only 10 options in the calculation, you could also use a switch instead of if expression for this, but this is one case where an if expression is more compact.

Avatar

Level 2

Thank you so much MinusZero

I didn't have any idea that formcalc code is much easier to understand than in javascript.

Avatar

Level 7

Glad to assist. I usually use Javascript but when you use it to create variables with a sum, it will concatenate rather than add. Formcalc treats it as a calculation.

Eg:

if ddl1 is 2 and ddl2 is 3.

var calc = ddl1 + ddl2 //in formcalc the variable will be 5 (2+3)

var calc = ddl1 + ddl2; //in javascript this will be a concatenated string and the variable will be 23 (2 concatenated to 3 = 23)

Oddly, if you were to multiply in javascript you get the calculated answer in the variable. *rolls eyes*