Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Introduction to Sitecore Personalize
Managing accounts and system settings
Identifying guests
Introduction to experiments
Introduction to experiences
Decisioning
View dashboards
Developer Center
Connecting to an external system
Using client-side JavaScript
Using server-side JavaScript
AI in Personalize
Glossary
  • Sitecore Personalize
  • Introduction to decisioning in Sitecore Personalize
  • Managing programmable decisions
  • Examples of programmable decisions

Examples of programmable decisions

The following are examples of programmable decisions to help get you started writing JavaScript in a a decision model variant.

Example 1: Retrieve custom attributes in a programmable decision

You can leverage custom guest attributes that are specific to your organisation, as inputs in decisioning. For example, use the guest's loyalty membership tier as an input in a decision model variant. This can ensure that you only display offers and content relevant to the guest's current membership tier.

Note

Ensure you set the Return Type as Map for the programmable decision.

RequestResponse
(function () {
 // change the guest data extension details for the required one. Snippet below gives
 //       "name": "loyalty"
 //       "key": "privilegeClub"

 var loyaltyData = {};
 for (var i = 0; i < guest.dataExtensions.length; i++) {
   if (guest.dataExtensions[i].name === 'loyalty' && guest.dataExtensions[i].key === 'privilegeClub') {
     loyaltyData = guest.dataExtensions[i].values;
     return loyaltyData;
   }
 }

 return loyaltyData;
})();

Example 2: Retrieve currency of closed session in a programmable decision

To ensure your organization is consistent in personalizing to the guest in the same currency that they chose in their closed session, you can create a programmable decision that retrieves the currency of the closed session. This is particularly useful in experiments that are designed for retargeting.

Note

Ensure you set the Return Type as String for the programmable decision.

RequestResponse
(function () {
 // for Abandoned Cart or Session Closed triggered flows, gets the closed session currency
 var sessionRef;
 if (entity) {
   sessionRef = entity.ref;
 }

 var sessionCurrency = "";
 for (var i = 0; i < guest.sessions.length; i++) {
   var session = guest.sessions[i];
   if (session.ref === sessionRef) {
     sessionCurrency = session.currency;
     break;
   }
 }
 return sessionCurrency;
})();

Using programmable outputs in decision tables

After creating a programmable decision, you can use its output as input for decision tables. This allows you to combine custom JavaScript logic with rule-based decision-making.

We'll show an example on how to use the output from Example 2 in a decision table to create currency-specific offers and pricing.

Step 1: Output from the programmable in Example 2

For a sample guest input with values for currency is USD, the programmable named Programmable 1 returns a an output like the following from a closed session:

RequestResponse
"outputs": [
        {
          "sessionCurrency": "USD"
        }
      ]
Step 2: Set up the Input column to use the programmable

To use the sessionCurrency output from the programmable in a decision table:

  1. Add an input column and select the programmable decision as input. In our example, you are using the programmable named Programmable 1.

  2. Specify the following for the Input Column:

    • Name of Column - name to use for the input. (example: Guest currency)

    • Choose Type - select the correct data type based on the indicated programmable output's type. (example: String)

  3. Once the Input column is added, continue configuring the decision table as normal, by setting up the output column and adding rules.

Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2026 Sitecore