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
to start, I believe you should try with a load() or with a a!locanVariables rather than a with()
Please post the entire code for your interface if you can (and when posting code, please use Insert --> Insert Code functionality here to keep code contained and readable, with proper indentation in tact). You can trim out any whole fields that are totally irrelevant to the dropdown in question, but it might help if you post the rest. With the bits and pieces you've posted so far, I can't tell (at all) where/how you're actually trying to set the value of local!categoryIcon.
That said, I do think Manuel's prior comment is probably on track - you appear to be defining the variable in a with() call but not providing a value to it there; issue being that with() variables can not be saved back into externally, they are meant to use as 100% autorefreshing variables.
I've already found more elegant way to do this in the meantime. For some reason this post (when I first tried to publish it) was marked as spam. I don't know why since it was my second post here ever.
While I was waiting for it to be approved by admins, I've found out how to solve this issue.
Is there a way I can remove my post or mark it as deprecated or something like that?
P.S. Sorry, Mike, for code formatting. This post has been written before you've taught me how to insert code in another topic :) Now, I use it properly.
No worries - I did think it sounded a little familiar, but didn't notice the post's age before replying.
I suggest you simply edit the original post and add some bolded text at the bottom reporting that you've resolved it, and (if you feel like writing it) a brief summary of what you did, just so potential future users who find their way here via search functionality might get a clue as to how to do it themselves instead of starting a new forum topic ;-)
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.