I want my form to only appear to users with certain value in their mobile worker custom fields

124 views
Skip to first unread message

Eric Stephan

unread,
May 22, 2017, 5:10:22 AM5/22/17
to commcare-users

Hi all --

I am making a new form called D2.

I want to use the "form display condition" to place a bit of logic that will make this form only appear visible if the mobile worker has "9001" inside the custom user field called org_code.

So I put the following string into the Form Display condition:

count(instance('commcaresession')/session/user/data/org_code) > 0 and instance('commcaresession')/session/user/data/org_code = '9001'


But... it crashes my app when I log in to a smartphone as a worker and try to see the available forms.

It says:  the instance "commcaresession" in expression "instance('commcaresession')/session/user/data/org_code" used by "/" does not exist in the form. Please correct your form or application.

..... Can you help me make the code correct so only those desired people can see this new form?

Thanks!

Eric

William Pride

unread,
May 22, 2017, 8:29:49 AM5/22/17
to commcare-users
Eric,

Your expression looks correct to me. Have you tried using the new `#session` syntax as shown at the bottom of the documentation here?

Cheers,
Will

--
You received this message because you are subscribed to the Google Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Stephan

unread,
May 22, 2017, 11:30:29 PM5/22/17
to commcare-users
that was good advice... but I made that change, updated the phone, very clearly synced the phone, and the error message stays exactly the same!!   which is weird because the error message still references that bit of text ("...commcaresession...")  that I actually removed from the code... but I guess that #session sort of gets substituted with the "instance(commcaresession)" text, that would explain why the message still says that?  I truly promise that I have updated...

I am submitting this as a bug report, but if you have ideas let me know.

Eric


William Pride

unread,
May 23, 2017, 7:34:14 AM5/23/17
to commcare-users
Filing a bug report sounds right, thanks Eric.

Cheers,
Will

Eric Stephan

unread,
May 25, 2017, 9:40:09 PM5/25/17
to commcare-users
Interesting. just FYI, the bug report people have found that the visibility logic statement is formed right... it works just fine when it's used for *module* visibility... but when the same statement is used for *form* visibility, it is generating the error.

The bug report folks said that they would talk to the developers and see if we could find out why.

Eric

jes...@agimpact.org

unread,
Jun 1, 2017, 9:27:48 PM6/1/17
to commcare-users
Hi I am having the same issue for filtering a form by user. I keep getting the same error!

William Pride

unread,
Jun 2, 2017, 5:23:32 PM6/2/17
to commcare-users
Hi Jessica,

This was a bug in CommCare that affected display conditions referencing the session for forms displayed at the menu root (IE "Display only forms" instead of "Display modules then forms." This will be resolved in CommCare 2.37. In the meantime the best workaround is to use the "Display modules then forms" option instead.

Apologies for the inconvenience. I'll update this thread when 2.37 becomes available.

Cheers,
Will

Reply all
Reply to author
Forward
0 new messages