Often it is useful to have access to certain system data, such as username, case id, or the unique device id, from within form entry. This can be achieved via the CommCare session instance.
|device id||instance('commcaresession')/session/context/deviceid||The unique ID for the entering device|
|username||instance('commcaresession')/session/context/username||The username of the user entering data|
|user id||instance('commcaresession')/session/context/userid||The GUID of the user entering data|
|app version||instance('commcaresession')/session/context/appversion||The identifier for the software application version performing form entry|
Note: the userid is not the same as the the commcare-user case id. In order to access the commcare-user case id, use this expression:
As you navigate through your mobile app to enter form entry, you will sometimes select cases. The ID of those cases are available in commcare session instance.
In normal workflows you only select one case. In such settings the case_id can be accessed using the instance('commcaresession')/session/data/case_id path.
If you are in a more advanced workflow (via advanced modules) you will be prompted for the 'case tag' of the case being loaded on HQ. If you set the case tag to 'load_mother' for example, then in the CommCare session instance you can access that case's id using the path instance('commcaresession')/session/data/case_id_load_mother
It is possible to attach custom data to users in CommCare and access that information within form entry. Details found at the 'Custom User Data' page.
There are several custom values that are provided in the custom user data:
|User's first name||instance('commcaresession')/session/user/data/commcare_first_name|
|User's last name||instance('commcaresession')/session/user/data/commcare_last_name|
|User's phone number||instance('commcaresession')/session/user/data/commcare_phone_number|
|User's primary location||instance('commcaresession')/session/user/data/commcare_location_id|