Get item value dynamically in a form field item transformation

Canelle Michel asked on March 27, 2018 15:13

Hi!

I've been using the Forms application and I'm populating the options of a multiple choice form control using a custom macro I implemented. So far, so good. But based on some custom condition, I'd like some of the options to be disabled (but they should appear so the user know they exist). The condition concerns the states of the others fields of the form.

That's why I would like to use the Item transformation in the Editing control settings part. However, I can't seem to even get to display the value of my item using the {%ColumnName%} syntax. I tried all the solutions listed on this Stackoverflow issue but none of them seems to work. Simply put, I don't know what to write in the Item transformation field in order for it to display the current item value.

What's even weirder is that I switched back to using a SQL query to populate my form control. I tried again to customize the item transformation with the value {%ColumnName%}. When writing {%ColumnName%} only, it works. But again, when trying to do something a bit more complicated, the value isn't displayed at all. For example, the following code doesn't work properly:

{%if (NextQuestion!=null&& NextQuestion=="Value 4") { %}
Fail
{% } else { %}
{%ColumnName%}
{%}#%}

I wonder if I'm doing anything wrong or if I should just to implement a custom form instead of using Kentico's built-in feature.

Thanks for your help!

Correct Answer

Dragoljub Ilic answered on March 27, 2018 16:10

Hi Canelle,

In assumption that 'NextQuestion' and 'CoulumnName' are exist as database fields in the table, you can paste them as plain text in item transformation and they should work. I faceted with the same issue while ago and it worked for me. Could be, that if you place it as macro condition (click on the arrow and add macro), that in the moment of resolving, fields are not picked up from DB which cause that all values are empty.

If you paste your condition directly in 'Item transformation' text box (without clicking on arrow), then you added a template which will be resolved later (when values are populated).

{%if (NextQuestion!=null&& NextQuestion=="Value 4") { %} Fail {% } else { %} {%ColumnName%} {%}|(identity)GlobalAdministrator%}

Best regards, Dragoljub

2 votesVote for this answer Unmark Correct answer

Recent Answers


Canelle Michel answered on March 27, 2018 16:52

Hi Dragoljub!

Thanks for your quick answer, indeed, this solved my issue (when using SQL Query as a datasource). I'm still not sure of what the difference is between clicking on the arrow and not clicking on the arrow, though. It won't resolve the expression at the same time?

So, I tried again with using macro as a datasource. And it also works, only with a little difference, I replaced {%ColumnName%} with {%Value%}. Thanks again!

Best regards,

Canelle

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.