Popular Help Content

No popular content.

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 Data

TypePathDetails
device idinstance('commcaresession')/session/context/deviceidThe unique ID for the entering device
usernameinstance('commcaresession')/session/context/usernameThe username of the user entering data
user idinstance('commcaresession')/session/context/useridThe GUID of the user entering data
app versioninstance('commcaresession')/session/context/appversionThe 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:

instance('casedb')/casedb/case[@case_type='commcare-user'][hq_user_id=instance('commcaresession')/session/context/userid]/@case_id


Session Data-- Referencing the Caseid inside Form Builder

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're referencing the case id in a form that created the case, you have to reference it as instance('commcaresession')/session/data/case_id_new_[case_type]_[n]. N indicates where that case falls in the order of cases being created in that form (is 0-indexed). For example, if your form is just creating one case of the one client case type, this will be: instance('commcaresession')/session/data/case_id_new_client_0. However, if your form is creating multiple cases, that last number will increment. You can find out the exact syntax by looking at the suite file.

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

Custom User Data

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 default values that are provided along with the user data:

DataPathFormat
User's first nameinstance('commcaresession')/session/user/data/commcare_first_name
User's last nameinstance('commcaresession')/session/user/data/commcare_last_name
User's phone numberinstance('commcaresession')/session/user/data/commcare_phone_number
User's primary locationinstance('commcaresession')/session/user/data/commcare_location_id
User's locationsinstance('commcaresession')/session/user/data/commcare_location_idsspace-separated list
User typeinstance('commcaresession')/session/user/data/commcare_user_type"web" or "commcare"