Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated the text and screenshots to reflect the new 'Required for user type' setting when creating the Custom User Fields

Custom User Data is useful if you want to be able to reference additional information about users in forms or cases.  By default, when you register a new Mobile WorkersWorker you can specify their username, first name, last name, and password. Similarly, you can specify a new Web User’s Email, Role, and Profile. Custom User Data is an advanced tool that enables you to store and reference any number of additional information about your mobile workers or web users. For example, you could create a category of users, additional location data, or other metadata.

...

Table of Contents
minLevel1
maxLevel2
outlinefalse
stylenone
typelist
printabletrue

Using Custom User Data

Configure Custom User Data

In this stage, you must define what data fields you want to collect for each mobile worker/web user.

  • On CommCareHQ navigate to Users -> Mobile WorkersView All.

  • Click on the "Edit User Fields" button in the middle of the screensidebar menu:

...

You will be brought to Edit User Fields page:

...

On this page, you have the option of adding fields to collect for mobile workers/ web users. For each field you will need to define the following:

  • User Property: The unique ID you can use to reference this property in the application builder. The property may not contain spaces. This field is analogous to a "Question ID" in the form builder.

  • Label: The field label that users will see when adding or editing a User in CommCareHQ.

  • Required: Indicates whether this field is required for each user. If it is marked as required then you will not be able to create or edit a mobile worker user without filling in this field. It will also show up The fields will appear with an ‘*' next to the label on the main "create mobile worker" pageCreate Mobile Worker", “Edit Mobile Worker’ and “Invite Web User” and “Edit Web User” pages.

  • Required for: This dropdown marks the field required for a specific user type. It is only activated when the checkbox is selected to mark the field required. The options include

    • Web users: The field will be required for creating/editing Web users

    • Mobile Workers: The field will be required for creating/editing Mobile workers. This is the default option for all the new fields being created.

    • Both: The field will be required for creating/editing both Mobile workers and Web users. This is the default option for all the existing fields created before October 31, 2024.

  • Validation: here Here you specify the type of input expected, the options are:

    • none:  you would like to use free text input;

    • choices: if you want to pre-define choices to appear as a dropdown; or

    • Regex: if you would like to use a regular expression for validation of the input. This is useful for validating that custom user data, custom location data, or custom product data follow a specified format. To design and test your regular expressions, you can use this website: http://www.regexr.com/.

...

This configuration would then update the Mobile Worker Registration Page to look like this:

...

...

The process remains ultimately the same for web users. The new UI for inviting a web user looks like this:

...

Now, it is also possible to edit Web User information once they accept the invite. This was previously available only to mobile workers.

...

Add Custom User Data

There are two ways to add custom user data - through the Mobile Workers section of Create/ Edit user pages on CommCareHQ, or through Bulk Upload.

CommCareHQ Web Users / Mobile Workers Page

After you configure the user data, each time you add a new web user/mobile worker the CommCareHQ user will be prompted to populate the field, in addition to the standard username and password fields. Required fields will have to be populated at the time of creating the web user/mobile worker, while other fields are optional. These can be filled in during registration , or when editing a worker an account.

Bulk User Upload

Multiexcerpt include macro
macro_uuid785c6088-0e28-4857-9b71-fdd34d840424
nameSoftware Plan - Standard
templateDataeJyLjgUAARUAuQ==
page[Internal] CommCare Public ManagementCommCare Help Site Design Guidance
addpanelfalse

You can use the Upload Mobile Workers in Bulk tool  or Upload Web users tool to add and update custom user data in bulk.

...

  • You cannot add new user data fields by just adding a new column in the Excel file. You must use the edit user fields page to set it up.

  • If a field is required and you upload a spreadsheet that does not have a value for that field for all users, the upload will fail.

  • If you change the Custom User Data for a user, the new values should sync down to the user's phone, any time the user syncs with the server as long as the user has filled in at least one form since the last sync.

Using Custom User Data in an Application

Storing Custom User Data in a Hidden Value

You will have to reference the user data through the commcaresession.  The format is generally instance('commcaresession')/session/user/data/custom_user_data_name

...

if(count(instance('commcaresession')/session/user/data/village) > 0, instance('commcaresession')/session/user/data/village, "Unknown")

Use a Custom User Data in a Display Condition

For example, to only show a particular question if the user is a supervisor (using the custom user data is_supervisor), add the following to a question's display condition.  Replace is_supervisor with the name of your custom user data and yes with the value you want to check for. 

count(instance('commcaresession')/session/user/data/is_supervisor) > 0 and instance('commcaresession')/session/user/data/is_supervisor= 'yes'

Accessing Phone Number and the User Name

Some additional information is also available through custom user data. They are automatically added to the data:

...

concat(instance('commcaresession')/session/user/data/commcare_first_name, " ", instance('commcaresession')/session/user/data/commcare_last_name)

Removing Custom User Data and Handling "Uncategorized" Data

As described above, you can remove fields on the "Edit User Fields" page. Removing a field does not necessarily remove the data that is attached to users.

...

This unrecognized data will still appear in mobile worker downloads and can still be edited. It will appear in columns marked "Uncategorized."

Limitations

There are instances where custom user data will not be activated when used in an Application that was copied from another one.