Saving document from the interface into CDT

This is the case:

- I have drop down field of categories

- Based on selected category corresponding image is shown

- Images are stored in constant which is array of documents

- The corresponding image is calculated by this rule (nothing really smart :) )

choose(
where(
{
ri!employee.category = "Boss",
ri!employee.category = "Team Leader",
ri!employee.category = "Business Analyst",
ri!employee.category = "Data Miner",
ri!employee.category = "Developer",
true
}
)[1],
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[1]
),
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[2]
),
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[3]
),
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[4]
),
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[5]
),
null
)

- I would like to capture the corresponding image and store it into rule input based on CDT field categoryIcon which is of document type

I was trying to capture it into local variable with with() function (in image component expression rule) and then save it on SUBMIT button into ri!categoryIcon.

This was my shot:

1) expression for image component saves it into local variable:

with(
local!categoryIcon,
choose(
where(
{
ri!employee.category = "Boss",
ri!employee.category = "Team Leader",
ri!employee.category = "Business Analyst",
ri!employee.category = "Data Miner",
ri!employee.category = "Developer",
true
}
)[1],
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[1]
),
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[2]
),
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[3]
),
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[4]
),
a!documentImage(
document: cons!EEDM_CATEGORY_AVATARS[5]
),
null
))

2) save on SUBMIT button:

a!buttonWidget(
label: "Submit",
saveinto: a!save(ri!employee.categoryIcon, local!categoryIcon),
submit: true,
style: "PRIMARY"
)

This is the error I'm getting:

I believe I'm capturing this local variable in a wrong place (image component expression)?

UPDATE: Found out better solution in the meantime:

There was no need for local variable at all.

Rule input ri!employee.categoryIcon is calculated based on ri!employee.category in the Category dropdown component code:

a!dropdownField(
                      label: "Category",
                      labelPosition: "ABOVE",
                      placeholderLabel: "--- Select a Value ---",
                      choiceLabels: cons!EEDM_EMPLOYEE_CATEGORY_LIST,
                      choiceValues: cons!EEDM_EMPLOYEE_CATEGORY_LIST,
                      value: ri!employee.category,
                      saveInto: {
                        ri!employee.category,
                        a!save(
                          ri!employee.categoryIcon,
                          choose(
                            where(
                              {
                                ri!employee.category = "Boss",
                                ri!employee.category = "Team Leader",
                                ri!employee.category = "Business Analyst",
                                ri!employee.category = "Data Miner",
                                ri!employee.category = "Developer",
                                true
                              }
                            )[1],
                            cons!EEDM_CATEGORY_AVATARS[1],
                            cons!EEDM_CATEGORY_AVATARS[2],
                            cons!EEDM_CATEGORY_AVATARS[3],
                            cons!EEDM_CATEGORY_AVATARS[4],
                            cons!EEDM_CATEGORY_AVATARS[5],
                            null
                          )
                        )
                      },
                      required: true,
                      validations: {}
                    )

Key point is a!save block in the saveInto property of Category dropdown. This is the place where my rather simple case-when rule calculates category icon depending on "just selected" category value and stores it into rule input for category icon.

From this point I can use wanted value from the rule input instead from local variable as i initially intended to.

UPDATE2: Read Stewart's answer for more advanced solution!

  Discussion posts and replies are publicly visible

Parents Reply Children
No Data