Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Introduction to Sitecore CDP
Data availability
Managing your account
Managing system settings
Managing guests
Batch segmentation
Data browser
Audience export
Dashboards
Developer center
  • Sitecore CDP
  • Audience export
  • JavaScript functions
  • Utility functions

Utility functions

Here's a list of utility functions you can call in an audience export.

${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.

  • "IE"

  • guest.country

secondString

string or object attribute representing a string

The string that goes at the end of the concatenated string.

  • "Dublin"

  • guest.city

Consider a guest's country and city in the guest profile:

RequestResponse
{
  "country": "IE",
  "city": "Dublin"
}

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:

RequestResponse
${concat("_", guest.country, guest.city)}

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 2. Example: Accessing the value for MemberCardCategory

Consider a guest profile with the following data extension object:

RequestResponse
{
  "dataExtensions": [
    {
      "name": "ext1",
      "values": {
        "MemberCardCategoryRenewalDate": "18/05/2025",
        "MemberCardBalance": 22000,
        "MemberCardType": "shop&miles",
        "MemberCardCategory": "premium",
        "MilesRequiredForMemberCardCategory": 3000
      }
    }
  ]
}

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:

RequestResponse
${getDataExtension(guest.dataExtensions, "ext1", "MemberCardCategory", "not-available")}

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:

RequestResponse
{
 "identifiers": [
    {
      "ref": "3d67f887-9e6f-55c7-9390-027e3fff5595",
      "createdAt": "2025-05-31T15:12:22.947Z",
      "modifiedAt": "2025-05-31T15:12:22.947Z",
      "provider": "BXLP",
      "id": "3bb8fb2092d1"
    }
  ]
}

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:

RequestResponse
${getIdentifier(guest.identifiers, "BXLP", "not-available")}

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.

  • "1984-04-15T01:04:00.000Z"

  • guest.dateOfBirth

  • guest.lastSeen

locale

string (BCP 47)

The language tag for the region that uses the date format of your choice.

  • "EN-US"

  • "EN-IE"

  • "EN-AU"

[timezone]

optional

string (time zone abbreviation)

The time zone that you want the formatted date in.

The default is "UTC".

  • "GMT"

  • "UTC"

Consider a guest's date of birth in the guest profile:

RequestResponse
{
  "dateOfBirth": "1984-04-15T01:04:00.000Z"
}

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:

RequestResponse
${formatDate(guest.dateOfBirth, "en-US")}

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.

  • "1984-04-15T01:04:00.000Z"

  • guest.dateOfBirth

  • guest.lastSeen

locale

string (BCP 47)

The language tag for the region that uses the time format of your choice.

  • "EN-US"

  • "EN-IE"

  • "EN-AU"

[timezone]

optional

string (time zone abbreviation)

The time zone that you want the formatted time in.

The default is "UTC".

  • "GMT"

  • "UTC"

Consider a guest's date of birth in the guest profile:

RequestResponse
{
  "dateOfBirth": "1984-04-15T01:04:00.000Z"
}

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:

RequestResponse
${formatTime(guest.dateOfBirth, "en-US")}

For the guest profile in the example above, the return value will be "3:04: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.

  • "1984-04-15T01:04:00.000Z"

  • guest.dateOfBirth

  • guest.lastSeen

locale

string (BCP 47)

The language tag for the region that uses the date and time format of your choice.

  • "EN-US"

  • "EN-IE"

  • "EN-AU"

[timezone]

optional

string (time zone abbreviation)

The time zone that you want the formatted date and time in.

The default is "UTC".

  • "GMT"

  • "UTC"

Consider a guest's date of birth in the guest profile:

RequestResponse
{
  "dateOfBirth": "1984-04-15T01:04:00.000Z"
}

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:

RequestResponse
${formatDateTime(guest.dateOfBirth, "en-US")}

For the guest profile in the example above, the return value will be "4/15/1984, 3:04: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.

  • "[email protected]"

  • guest.email

Consider a guest's email address in the guest profile:

RequestResponse
{
  "email": "[email protected]"
}

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:

RequestResponse
${sha256(guest.email)}

For the guest profile in the example above, the return value will be hashed and securely exported.

Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2025 Sitecore