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

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

Eric,

Your expression looks correct to me. Have you tried using the new
#session syntax as shown at the bottom of the documentation here
https://confluence.dimagi.com/display/commcarepublic/Module+Filtering?

Cheers,
Will

··· On Mon, May 22, 2017 at 5:10 AM, Eric Stephan wrote:

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


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.

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

Filing a bug report sounds right, thanks Eric.

Cheers,
Will

··· On Mon, May 22, 2017 at 11:30 PM, Eric Stephan wrote:

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


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.

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

Hi I am having the same issue for filtering a form by user. I keep getting
the same error!

··· On Friday, May 26, 2017 at 11:40:09 AM UTC+10, Eric Stephan wrote: > > 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 > >

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

··· On Thu, Jun 1, 2017 at 9:27 PM, wrote:

Hi I am having the same issue for filtering a form by user. I keep getting
the same error!

On Friday, May 26, 2017 at 11:40:09 AM UTC+10, Eric Stephan wrote:

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


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.