Way to capture the current user's userID?

Hi folks -- I've meant to ask this for a while --

Is there a way that a form could use some special system variable to
capture the userID of the current user? Perhaps, for instance, it could
stick that into a hidden variable, output it to the app screen for some odd
reason, save it as a case property, etc.

Is that possible?

(I do know that the data already saves the userID in the normal application
data when you export it or view it in commcareHQ.)

Thanks!
Eric

Eric,

The user's ID is in the Session Instance, which is a special Document made
available to the form entry engine in CommCare very similarly to the way
that Lookup Tables are. You can basically reference the session in your
form as if it was a lookup table, and its structure is documented here:
commcaresession · dimagi/commcare-core Wiki · GitHub, and the Instance
Connector automatically inserted by CommCare HQ is named 'commcaresession'

So to get the user's ID inside the form you would use the expression

instance('commcaresession')/session/context/userid

-Clayton

··· On Fri, Apr 10, 2015 at 10:27 AM, Eric Stephan wrote:

Hi folks -- I've meant to ask this for a while --

Is there a way that a form could use some special system variable to
capture the userID of the current user? Perhaps, for instance, it could
stick that into a hidden variable, output it to the app screen for some odd
reason, save it as a case property, etc.

Is that possible?

(I do know that the data already saves the userID in the normal
application data when you export it or view it in commcareHQ.)

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.

Thanks much -- that sounds handy! I'll try it out.

Thanks -- Eric

··· On Friday, April 10, 2015 at 10:12:06 PM UTC+7, Clayton Sims wrote: > > Eric, > > The user's ID is in the Session Instance, which is a special Document made > available to the form entry engine in CommCare very similarly to the way > that Lookup Tables are. You can basically reference the session in your > form as if it was a lookup table, and its structure is documented here: > https://github.com/dimagi/commcare/wiki/commcaresession, and the Instance > Connector automatically inserted by CommCare HQ is named 'commcaresession' > > So to get the user's ID inside the form you would use the expression > > instance('commcaresession')/session/context/userid > > -Clayton > > > On Fri, Apr 10, 2015 at 10:27 AM, Eric Stephan <este...@fhi360.org > wrote: > >> >> Hi folks -- I've meant to ask this for a while -- >> >> Is there a way that a form could use some special system variable to >> capture the userID of the current user? Perhaps, for instance, it could >> stick that into a hidden variable, output it to the app screen for some odd >> reason, save it as a case property, etc. >> >> Is that possible? >> >> (I do know that the data already saves the userID in the normal >> application data when you export it or view it in commcareHQ.) >> >> 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-user...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > >

Hi Clayton -- I just tried this advice of yours from a while ago...

I put an OUTPUT command inside a label in my form, which displayed:
instance('commcaresession')/session/context/userid

But what was displayed was in fact a long string that looked like...
6afe553eba48371......

What I was hoping to see was the plain username, like "jsmith" or "clinic24"

Can you tell me where my thinking, or my attempt, was wrong?

thanks for this!
Eric

··· On Friday, April 10, 2015 at 10:12:06 PM UTC+7, Clayton Sims wrote: > > Eric, > > The user's ID is in the Session Instance, which is a special Document made > available to the form entry engine in CommCare very similarly to the way > that Lookup Tables are. You can basically reference the session in your > form as if it was a lookup table, and its structure is documented here: > https://github.com/dimagi/commcare/wiki/commcaresession, and the Instance > Connector automatically inserted by CommCare HQ is named 'commcaresession' > > So to get the user's ID inside the form you would use the expression > > instance('commcaresession')/session/context/userid > > -Clayton > > > On Fri, Apr 10, 2015 at 10:27 AM, Eric Stephan <este...@fhi360.org > wrote: > >> >> Hi folks -- I've meant to ask this for a while -- >> >> Is there a way that a form could use some special system variable to >> capture the userID of the current user? Perhaps, for instance, it could >> stick that into a hidden variable, output it to the app screen for some odd >> reason, save it as a case property, etc. >> >> Is that possible? >> >> (I do know that the data already saves the userID in the normal >> application data when you export it or view it in commcareHQ.) >> >> 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-user...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > >

Sorry -- Please *ignore *my last question! I figured it out -- I just had
to change the word"userid" to "username".

THANKS
Eric

Eric,

Glad to hear you were able to figure this out.

for reference (Warning! technobabble follows), the commcare session
instance schema is available here:
commcaresession · dimagi/commcare-core Wiki · GitHub and outlines what
information is in the session and where.

-Clayton

··· On Wed, Jun 10, 2015 at 2:48 AM, Eric Stephan wrote:

Sorry -- Please *ignore *my last question! I figured it out -- I just had
to change the word"userid" to "username".

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.