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
  • 0
    Certified Lead Developer

    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.

Reply
  • 0
    Certified Lead Developer

    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.

Children
  • 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.

  • +1
    Certified Lead Developer
    in reply to ivanm0004

    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 ;-)