---
title: "Utility functions"
slug: "utility-functions"
abstract: "Useful utility functions to call in an audience export in Sitecore CDP."
---
# Utility functions

Here's a list of utility functions you can [call in an audience export](https://doc.sitecore.com/cdp/en/users/sitecore-cdp/audience-export/javascript-in-the-export.html#UUID-e0fcc0c5-b3e4-cbab-1a1c-81f5c3fee3e4_section-idm4642469535550433964492091815 "Calling utility functions") 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.<br><br>To not use any separator string, set this value to an empty string `""`. | <ul><li>`"+"`</li><li>`"-"`</li><li>`""`</li></ul> |
| `firstString` | string or object attribute representing a string | The string that goes at the beginning of the concatenated string. | <ul><li>`"IE"`</li><li>`guest.country`</li></ul> |
| `secondString` | string or object attribute representing a string | The string that goes at the end of the concatenated string. | <ul><li>`"Dublin"`</li><li>`guest.city`</li></ul> |

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

```json
{
  "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:

```javascript
${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.<br><br>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]`<br><br>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:

```json
{
  "dataExtensions": [
    {
      "name": "ext1",
      "values": {
        "MemberCardCategoryRenewalDate": "18/05/2026",
        "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:

```javascript
${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.<br><br>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]`<br><br>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:

```json
{
 "identifiers": [
    {
      "ref": "3d67f887-9e6f-55c7-9390-027e3fff5595",
      "createdAt": "2026-05-31T15:`12:22`.947Z",
      "modifiedAt": "2026-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:

```javascript
${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](https://en.wikipedia.org/wiki/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. | <ul><li>`"1984-04-15T01:`04:00`.000Z"`</li><li>`guest.dateOfBirth`</li><li>`guest.lastSeen`</li></ul> |
| `locale` | string ([BCP 47](https://www.techonthenet.com/js/language_tags.php)) | The language tag for the region that uses the date format of your choice. | <ul><li>`"EN-US"`</li><li>`"EN-IE"`</li><li>`"EN-AU"`</li></ul> |
| `[timezone]`<br><br>optional | string ([time zone abbreviation](https://www.timeanddate.com/time/zones/)) | The time zone that you want the formatted date in.<br><br>The default is `"UTC"`. | <ul><li>`"GMT"`</li><li>`"UTC"`</li></ul> |

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

```json
{
  "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:

```javascript
${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](https://en.wikipedia.org/wiki/ISO_8601)) or object attribute representing such a string | The ISO date to transform, for example, the time an order. | <ul><li>`"1984-04-15T01:`04:00`.000Z"`</li><li>`guest.dateOfBirth`</li><li>`guest.lastSeen`</li></ul> |
| `locale` | string ([BCP 47](https://www.techonthenet.com/js/language_tags.php)) | The language tag for the region that uses the time format of your choice. | <ul><li>`"EN-US"`</li><li>`"EN-IE"`</li><li>`"EN-AU"`</li></ul> |
| `[timezone]`<br><br>optional | string ([time zone abbreviation](https://www.timeanddate.com/time/zones/)) | The time zone that you want the formatted time in.<br><br>The default is `"UTC"`. | <ul><li>`"GMT"`</li><li>`"UTC"`</li></ul> |

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

```json
{
  "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:

```javascript
${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](https://en.wikipedia.org/wiki/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. | <ul><li>`"1984-04-15T01:`04:00`.000Z"`</li><li>`guest.dateOfBirth`</li><li>`guest.lastSeen`</li></ul> |
| `locale` | string ([BCP 47](https://www.techonthenet.com/js/language_tags.php)) | The language tag for the region that uses the date and time format of your choice. | <ul><li>`"EN-US"`</li><li>`"EN-IE"`</li><li>`"EN-AU"`</li></ul> |
| `[timezone]`<br><br>optional | string ([time zone abbreviation](https://www.timeanddate.com/time/zones/)) | The time zone that you want the formatted date and time in.<br><br>The default is `"UTC"`. | <ul><li>`"GMT"`</li><li>`"UTC"`</li></ul> |

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

```json
{
  "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:

```javascript
${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](https://en.wikipedia.org/wiki/SHA-2) 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. | <ul><li>`"jane.doe@myretailsite.com"`</li><li>`guest.email`</li></ul> |

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

```json
{
  "email": "jane.doe@myretailsite.com"
}

```

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:

```javascript
${sha256(guest.email)}

```

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