Add a programmable decision to the decision canvas
The following section details how to add a programmable decision to a decision model variant.
To add a programmable decision to a decision model:
-
Click and drag the Programmable component from the palette to the decision canvas and click the Edit
icon.
TipEach time you add a programmable to the canvas, a unique Programmable tab displays. You can close the tabs without deleting any programmable decisions.
-
On the Settings tab, complete the following fields:
-
Programmable Name: Edit the name of the programmable decision.
-
Output Reference: Edit the name of the output reference. An output reference enables you to use the output of a programmable decision in another decision. Sitecore Personalize stores the return value of the main() function as an output reference. Apply the following naming conventions:
-
Ensure that the output reference name contains no spaces.
-
The first character must either be an ASCII letter (either uppercase or lowercase), a letter that complies with Unicode variable naming conventions, or an underscore (_) character. Do not use a number as your first character.
-
Subsequent characters must be letters, numbers, or underscores.
-
The output reference name must not be a reserved word. A reserved word is a keyword that is reserved by JavaScript functions or other uses that cannot be used as identifiers such as variable names, function names, and class names.
-
Each output reference name must be unique within a decision canvas.
-
-
Type: Select one of the following options:
-
String - A text value.
-
Boolean - A binary value that can either be true or false.
-
Integer - A number value.
-
Long - An integer that is longer than the size of the standard Integer type. This is useful for large numbers.
-
Date - Represents a date value.
-
Map - Returns the entire object for the next decision to use.
-
-
-
Enter the JavaScript for the Programmable Decision. To automatically format and indent the JavaScript code, click
.
We recommend that you familiarize yourself with supported and unsupported JavaScript functions.
You can use the Immediately Invoked Function Expression(IIFE).
TipAs you write, a code editor library displays with attributes and snippets that you can select from.
-
You can import one or more JS module functions, instead of having to create the code from scratch. To do this, click
and choose the JS modules, as shown in the following image:
TipTo open the JS module, hover over the name and click
. To view a description, hover over the name and click
.
The number of imported JS modules is updated on the
icon. Sitecore Personalize inserts the code from the JS modules when the programmable decision compiles.
-
Click the Data tab on the coding pane to copy a guest data model attribute or path and paste into the JavaScript editor. Click the
icon and choose one of the following options:
-
To view a random guest's attributes based on guest type, click in the search box and choose Quick Select Customer or Quick Select Visitor. The system selects a guest who was recently active.
-
To select fields from a specific guest, enter their unique identifier into the search box. For example, if you want to use segment membership as dynamic data, search for a guest who is a member of the segment. You can search for a guest using, for example, an email address, other unique identifier or browser ID.
NoteIf there is a guest whose data you often use when configuring or testing code, just click the star icon to bookmark the guest so you no longer have to search for them.
-
-
Click the Data tab on the coding pane to copy the attributes or paths from the decision model response and paste it into the JavaScript editor. As you write your JavaScript, ensure that you consider the data limits in decisioning.
-
Click the Save button to save your changes.