Return text in an alternative form

Digital Team asked on January 11, 2017 18:03

Hi,

I have a form that has a field with a dropdownlist control, this dropdown uses a sql query that feeds with a key:value list. Now I have a alternative view to display the selected item on the dropdown, so i'm trying to show the Value, if I use the Label control I only get the ID that is saved on the DB.

What would be the best and easiest way to get the Value when displaying the alternative form?

Thanks

Correct Answer

Digital Team answered on January 12, 2017 16:13

http://stackoverflow.com/questions/33806524/query-custom-table-in-form-builder-auto-responder

This worked perfectly.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on January 11, 2017 18:11 (last edited on January 11, 2017 18:11)

Couple of options.

1: You can use a Label, and as part of the configuration there is the "Output Format" which you can put a macro (using {% Value %} as the value of it), so you would have to write a macro to get it:

SiteObjects.Forms.Where("FormID = "+convert.ToInt(Value, 0))[0]["CodeName"]

2: Keep it a Drop Down list, just use a macro to 'enable' or 'disable' it based on if !string.isnullorwhitespace(TheDropDownFieldName.Value). This will show a drop down that can't be changed with the value set to the one in the database.

1 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on January 11, 2017 19:45 (last edited on December 10, 2019 02:30)

As far as I understand you probably want to show to a returning user his previous answer in order to avoid him answering twice the same question. For example if a user has selected his category from drop down - no need to answer again.

In your form data you have to have a field that a connects form record to your current user For example let it be email and you want to get CategoryID - your macro should be

{%SiteObjects.Forms["YourFormCodeName"].Items.Where("email='" + CurrentUser.Email + "'").FirstItem.CategoryId|(identity)GlobalAdministrator%}

Now you can set selected item using jquery and disable the dropdown.:)

P.S. You can get the text instead of value, but you need to create a custom macro, because you need to run your query.

1 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on January 12, 2017 08:53

When you use label to present some value it gives you an option to select transformation for your data, e.g. Yes/No transformation for bool values, User name from user ID, etc. You could implement your custom transformation to convert key to a value. Here is documentation on UniGrid transformations.

Another option would be custom macro.

P.S. In case you are going to present multiple items it is recommended to cache all key/value pairs, so you do not query SQL server for each item.

1 votesVote for this answer Mark as a Correct answer

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