Problem: nesting Selected function inside the If function is not working

495
7
Jump to solution
12-07-2022 12:21 PM
vocono1953
New Contributor II

The selected function returns an integer with is the evaluated by the If function that should return text to display in a text field. It’s not working. No doubt a syntax error but cannot see the error.

if(selectede(${lst_crew_cnt}) > 1, 'Data Entry Staff','Gardener')

It’s placed in the calculate field for the target text field.

Thank you for any help you can give.

--Bob

0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

Form seems to work fine for me with the single quotes.

To wait for user input you can do 2 ways.  

One is to use relevant of  ${lst_crew_cnt} != ''.  That way the field is not shown until the crew count is picked.  Not sure why you are doing 1 and One.  May be a data issue later esp if you want to use it as a number.

The other way if you want to always see the field is to wrap your if in another if, again checking for empty.

if(${lst_crew_cnt} != '',if(selected(${lst_crew_cnt},'1'),'Data Entry Staff','Gardener'),'')

You have a ton of groups in here and it is going to be pretty slow for you staff to fill out this form.  Basically they have to open a group for almost every question.  I would at least expand all of these but really the form is so short I would remove all the groups.  I personally think all that green burns the eyes but that is just an opinion.  In my experience all these font tags will become a pain when trying to use the data since it will be burned in there.  Take a look at it in a web map and see.  Again on such a simple form I do not think all this formatting is really needed.  Just an idea.  Not sure if this would bother color blind users.

Hope that helps

View solution in original post

0 Kudos
7 Replies
DougBrowning
MVP Esteemed Contributor

First you have a typo with an extra e.  You also have the ) in the wrong spot selected(question, value)

if(selectede(${lst_crew_cnt}) > 1, 'Data Entry Staff','Gardener')

Second selected actually returns True/false and not a number.  count-selected does that.

So you want this expect you have no other side of the if so not sure what you want there.

if(selected(${lst_crew_cnt}, 'Data Entry Staff'), 'Gardener', 'else??')

Hope that helps

0 Kudos
vocono1953
New Contributor II

Thank you for explaining what this selected function does. It was rewritten to use as a boolean expression.

if(selected(${lst_crew_cnt},'1'),'Data Entry Staff','Gardener')

The second parameter ('1') is the name used in the choice sheet for 'One', the label displayed in the list. If 'One' is selected, then 'Data Entry Staff' is displayed, else 'Gardener'. Each to be displayed in txt_gardener_role.

The problem is an error message saying the second parameter should have quotes. I added them but the same message appears. Once again, I'm not understanding why this generates an error.

Thanks again for any help.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Sorry hard to tell here but your formula looks correct now.  Where is this in a calc field?  Is it string, number, etc?  A screen shot or form would help.  Maybe try " double quotes and see if something is off there.  Something else is going on.

0 Kudos
vocono1953
New Contributor II

Using double quotes worked! Thank you.

Is there a way to prevent the formula from executing before a number is selected? The IF function is selecting the True item by default.

You mentioned that “something else is going on.” I think you mean it’s maybe a side-effect. I’ve attached the xlsx file as requested. Thanks again.

0 Kudos
vocono1953
New Contributor II

The If function is on line 24.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Form seems to work fine for me with the single quotes.

To wait for user input you can do 2 ways.  

One is to use relevant of  ${lst_crew_cnt} != ''.  That way the field is not shown until the crew count is picked.  Not sure why you are doing 1 and One.  May be a data issue later esp if you want to use it as a number.

The other way if you want to always see the field is to wrap your if in another if, again checking for empty.

if(${lst_crew_cnt} != '',if(selected(${lst_crew_cnt},'1'),'Data Entry Staff','Gardener'),'')

You have a ton of groups in here and it is going to be pretty slow for you staff to fill out this form.  Basically they have to open a group for almost every question.  I would at least expand all of these but really the form is so short I would remove all the groups.  I personally think all that green burns the eyes but that is just an opinion.  In my experience all these font tags will become a pain when trying to use the data since it will be burned in there.  Take a look at it in a web map and see.  Again on such a simple form I do not think all this formatting is really needed.  Just an idea.  Not sure if this would bother color blind users.

Hope that helps

0 Kudos
vocono1953
New Contributor II

Just used single quotes and it works. Go figure.

${lst_crew_cnt} != '' worked.

I task your points on the colors and groups. I'll bring them up at our next meeting.

Thank you for all your help.