Profile and system variables in scripting
You cannot use scripting to create new profile variables; however, you can use it to get and set values for existing profile variables. Profile variable value updates occur asynchronously through scripting.
- The member object is available as a root object in onComplete and onLoad events.
- You cannot dynamically pass the profile name to get the profile.
- You can access and set profile variable values for anonymous responses.
- While previewing the survey, you can access and set profile variable values and these values will be accessible by scripting. However, which profile variables are accessible in the Preview dialog is limited to the profile variables referenced in the survey (for example, in survey logic, masking, or piping).
- The member object will be
null if respondentUrn does not match any of the items below:
urn:alida-sparq-member:{memberId}
orurn:alida-survey-preview-user:{admin user Id}
- If you are using scripting to get and set profile variable values, using Profile actions in the same survey is not recommended because they may interfere with and overwrite each other's values, causing unexpected results. All the profile variables are loaded at the beginning of the response. As the respondent proceeds through the survey, scripting will get and set values, which will be sent to the community and update member values accordingly. However, Profile actions do this at the end of the response.
- Identity profile variable values must be unique per member.
Function or property | Description |
---|---|
member.id;
|
The member's unique ID. This property is read-only. |
|
Gets and sets a numeric profile variable value. In this function example, you are getting the Age value, which is 10, and then resetting it to 12. |
|
Gets and sets Single Choice profile variable values. The values you set must already exist in the profile variable. In this function example, you are getting the current value (Vancouver) and setting it to Toronto. |
|
Gets and sets Multiple Choice profile variable values. The values you set must already exist in the profile variable. In this function example, you are getting the current values array (Dog and Cat) and setting the profile variable values to Parrot and Hamster. |
|
Gets and sets Date profile variable values. Returns a JavaScript Date object. Dates are stored in UTC format. In this function example, you are getting the existing value for the Date profile variable lastPurchasedDate, and then setting the new date to the current date. |
Access levels for different types of profile or system variables
Depending on the profile or system variable, the access level varies from no access to read-only and read/write.
Access level | Profile or system variable | Notes |
---|---|---|
No access |
|
Accessing a restricted system variable will result in an error. |
Read-only |
|
Setting a read-only system variable value will result in an error. |
Read/write |
|