- JavaScript functions
Utility functions
Here's a list of utility functions you can call in an audience export in a field on the Output structure tab.
${concat(separatorString, firstString, secondString)}
This function returns a string created by appending the second string to the end of the first string. You can specify a separator string between the two strings.
sidebar. Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
separatorString | string | The string that goes between the first string and the second string. To not use any separator string, set this value to an empty string "". |
|
firstString | string or object attribute representing a string | The string that goes at the beginning of the concatenated string. |
|
secondString | string or object attribute representing a string | The string that goes at the end of the concatenated string. |
|
Consider a guest's country and city in the guest profile:
You can concatenate the values for country and city and include the concatenated string in the output by entering the following into an Attribute value field on the Output structure tab:
For the guest profile in the example above, the return value will be "IE_Dublin".
${getDataExtension(extObj, extName, extKey[, fallback])}
This function returns a data extension value available in the guest profile.
sidebar. Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
extObj | object | The reference to the data extensions object in the guest profile. You must set this value to guest.dataExtensions. | guest.dataExtensions |
extName | string | The extension name. | "ext1" |
extKey | string | The extension key for the value you want to include in the output. | "MemberCardCategory" |
[fallback]optional | string | The fallback value to be included in the output if the extension doesn't exist in the guest profile. | "not-available" |
Example 4. Example: Accessing the value for MemberCardCategory
Consider a guest profile with the following data extension object:
You can access the value for MemberCardCategory and include it in the output by entering the following into an Attribute value field on the Output structure tab:
For the guest profile in the example above, the return value will be "premium".
For a guest profile that doesn't have this data extension, the return value will be "not-available".
${getIdentifier(identifiersObj, provider[, fallback])}
This function returns the guest's identifier ID if available in the guest profile.
sidebar. Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
identifiersObj | array of objects | The reference to the identifiers object in the guest profile. You must set this value to guest.identifiers. | guest.identifiers |
provider | string | The name of your organization's identity system, external to Sitecore CDP, that provided the unique guest identifier. | "BXLP" |
[fallback]optional | string | The fallback value to be included in the output if these identifiers don't exist in the guest profile. | "not-available" |
Consider a guest's identifiers array of objects in the guest profile:
You can include the value for identifiers.id in the output by entering the following into an Attribute value field on the Output structure tab:
For the guest profile in the example above, the return value will be "3bb8fb2092d1".
For a guest profile that doesn't have these identifiers, the return value will be "not-available".
${formatDate(date, locale[, timezone])}
This function formats an ISO date into a date that's easier to read, using the date format of your choice.
sidebar. Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
date | string (ISO 8601) or object attribute representing such a string | The ISO date to transform, for example, the guest's date of birth or last seen date. |
|
locale | string (BCP 47) | The language tag for the region that uses the date format of your choice. |
|
[timezone]optional | string (time zone abbreviation) | The time zone that you want the formatted date in. The default is "UTC". |
|
Consider a guest's date of birth in the guest profile:
You can format this date for the US English date format and include it in the output by entering the following into an Attribute value field on the Output structure tab:
For the guest profile in the example above, the return value will be "4/15/1984".
${formatTime(time, locale[, timezone])}
This function formats an ISO date into a time that's easier to read, using the time format of your choice.
sidebar. Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
time | string (ISO 8601) or object attribute representing such a string | The ISO date to transform, for example, the time an order. |
|
locale | string (BCP 47) | The language tag for the region that uses the time format of your choice. |
|
[timezone]optional | string (time zone abbreviation) | The time zone that you want the formatted time in. The default is "UTC". |
|
Consider a guest's date of birth in the guest profile:
You can format this date for the US English time format and include it in the output by entering the following into an Attribute value field on the Output structure tab:
For the guest profile in the example above, the return value will be "3
:00 AM".${formatDateTime(time, locale[, timezone])}
This function formats an ISO date into a date and time that's easier to read, using the date and time format of your choice.
sidebar. Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
time | string (ISO 8601) or object attribute representing such a string | The ISO date to transform, for example, the guest's date and time of birth or last seen date and time. |
|
locale | string (BCP 47) | The language tag for the region that uses the date and time format of your choice. |
|
[timezone]optional | string (time zone abbreviation) | The time zone that you want the formatted date and time in. The default is "UTC". |
|
Consider a guest's date of birth in the guest profile:
You can format this date for the US English date and time format and include it in the output by entering the following into an Attribute value field on the Output structure tab:
For the guest profile in the example above, the return value will be "4/15/1984, 3
:00 AM".${sha256(value)}
This function hashes a value using the SHA-256 algorithm to ensure that data is securely exported.
sidebar. Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
value | string or object attribute representing such a string | The data to hash before it's exported. |
|
Consider a guest's email address in the guest profile:
You can hash this email address and include it in the output by entering the following into an Attribute value field on the Output structure tab:
For the guest profile in the example above, the return value will be hashed and securely exported.