How should I refer to a code list value in an expression?

  • Asked
  • Active
  • Viewed 10561 times
0

Hi,

When I refer to a code list value in e.g. a relevancy expression of an attribute, should I use the code or the code label? For instance I want that an attribute is relevant when the code attribute "accessibility" takes the value 1 (code label: "Accessible"). Which of the following is correct?

Relevant when: accessibility=1

or

Relevant when: accessibility="Accessible"

Thanks!

1

Accepted answer

Hi, when referencing a code attribute, only the code will be considered (don't forget that you can define surveys in multiple languages and you can define different labels for the same code item...). The right expression will be: accessibility='1'


Don't forget that the code is a alphanumeric value, so you have to wrap it into single or double quotes when you want to use it as a value in an expression. Thanks.

1

Accepted answer

Dear user,
If accessibility is a Boolean attribute you can use just:

  • accessibility (that is equivalent to accessibility = true() )
  • not(accessibility) (equivalent to accessibility = false() )

accessibilty = '1' or accessibility = '0' can be used only if accessibility is a Code attribute.

Thanks,
Open Foris Team

0

Accepted answer

Hi I know this discussion thread is slightly dated, but I would like to add some points from my own experience for other users who are looking for information regarding using expressions in the

Survey Designer >>> Schema >>> Attribute >>> Relevant >>> Only when expression is verified


If 'accessibility' is a Boolean attribute, you can use


  • accessibility = '1'

meaning that this survey attribute only appears when 'accessibility' was assessed as '1' i.e. not accessible, or you can write the following expression


  • accessibility = '0'

meaning that this next attribute only appears when 'accessibility' was assessed as '0' i.e. accessible.


If 'accessibility' is instead a Code attribute with multiple code elements as listed in Survey Designer >>> Code Lists, you may use similar expressions as before to configure your survey such that the next attribute only appears when a certain code list element (numerical) is selected,


  • accessibility = '5'

meaning that the next attribute only appears when 'accessibility' was assessed as '5'.


Also, to include multiple conditions for the expression, you can use simple conditional expressions


  • (accessibility = '2') or (accessibility = '3')

meaning that this next attribute only appears when 'accessibility' was assessed as either '2' or '3'


If you have another code attribute (e.g. 'agriculture_type'), then you can write the following expression


  • (accessibility = '2') and (agriculture_type = '3')

meaning that this next attribute only appears when 'accessibility' and 'agriculture_type' was assessed as '2' and '3' respectively.


A less common example, is if you want a question to pop up when any list element was selected in the previous question. In this case, you would write the following expression


  • agriculture_type

meaning that if you select any code list element under 'agriculture_type', this next survey question will appear.


Finally, you can write the following expression to exclude certain scenarios


  • agriculture_type != '3'

meaning that the next survey question will pop up as long as you select any other code element other than '3' for 'agricultural_type'. To clarify != is the notation used for 'not equals to'


Hope you will find this helpful.

Your answer

Markdown text. Shortcuts: Ctrl+B bold, Ctrl+I italic, Ctrl+K link, Ctrl+E code, Ctrl+Shift+V paste as plain text. Tab indents list items and code; press Escape, then Tab, to leave the text box.

Insert an image

Say what the image shows, for people who can't see it.

Keyboard shortcuts

Anywhere

?
Show this list
/
Search
g h
Go to the home page
g q
Go to the questions
g t
Go to the tags
g u
Go to the users
a
Ask a question

Lists of questions

j k
Next or previous question
Enter
Open the question

Question pages

j k
Next or previous post

Shortcuts never apply while you type in a text field. Members can turn them off in their preferences.