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
So, there are a few things worth commenting on here:
Once you have the list in a database table you can use an a!queryEntity to retrieve the full list, extract the text column to be the list of 'choiceLabels' for your dropdown, and extract the integer column for the list of 'choiceValues', and your save() and value() for your dropdown simply saves the relevant value to your CDT's attribute.
And that should be it.
I agree with you. This was rather primitive test while I was making babysteps (or crawling) learning Appian
While I was waiting for this post to be approved I've run into some "best practices" topics and learned about stuff you're talking about.
Now' I'm aware that generally speaking we should make codebook tables in database and then use some rules to fetch wanted values instead of creating temporary "in-code" decision logic. I believe decision objects are also valid choice sometimes?
In my case codebook table with category ID, category label and category Icon would be the best solution. Then I could fetch whole record from that table in my Category dropdown and then use its columns to populate choice labels, choice values, ri!category and ri!categoryIcon.