Configure an input column with JavaScript

Abstract

How to configure an input column with JavaScript. This is useful when you want to use custom code as input in the decision table (Sitecore Personalize).

This topic describes how to configure an input column to use JavaScript as input in the decision table. This is useful when you want to use custom code as input in the decision table.

To configure an input column with JavaScript:

  1. Create a decision table.

  2. On the Decision Table tab, next to the Input table header, click Add Column. The Add Column window displays.

  3. Click Script .

  4. In the Name Column field, enter an intuitive name. The name you enter displays as a column header.

  5. Click Add. The JavaScript editor displays.

  6. In the Output Reference field, enter an output reference for the input. This enables you to select the output of the decision table as input in another decision. You must apply the following naming conventions:

    • Do not use hyphens or 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 (_).

    • Do not use 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.

  7. In the Type drop-down list, click the format type of the variable that you want to use as input in the decision table. This is the format type of the variable that is returned from the JavaScript and used as an input in the decision table:

    • 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.

    • List - returns an array for use in a single variable.

    • Map - returns the entire object for the next decision to use.

  8. To copy and paste data model attributes and paths to use as dynamic data in JavaScript, click the Data tab. To see the data model, you must search for a guest by email address, or click Quick Select Customer or Quick Select Visitor. For example, if you want to use segment membership as dynamic data, search for a guest who is a member of the segment.

  9. Enter the JavaScript in the editor and click the gear icon to use the following features as required:

    • Validate - click this button to validate the syntax of your code.

    • Night mode - click this link to change the background of the Editor to black. To toggle back to a white background, click the Day mode link.

    • Copy all - click this link to copy all the JavaScript to your clipboard.

    • Upload - click this link to upload JavaScript as a .txt file from your local drive.

    • Download - click this link to download JavaScript as a .txt file from your local drive. You might want to do this if you want to reuse the JavaScript in another Decision Model.

  10. Click Done. You return to the Decision Table tab.

  11. To continue creating your decision table you can configure an output column.