---
title: "Add a programmable decision to the decision canvas"
slug: "add-a-programmable-decision-to-the-decision-canvas"
abstract: "Describes how to add a programmable decision to a decision model variant."
---
# 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:

1. Click and drag the **Programmable** component from the palette to the decision canvas and click the **Edit** ![Edit_decision_table.png](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/Edit_decision_table.png) icon.

    > [!tip]
    > Each time you add a programmable to the canvas, a unique **Programmable** tab displays. You can close the tabs without deleting any programmable decisions.

2. 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](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/introduction-to-decisioning-in-sitecore-personalize/managing-decision-model-variants-in-sitecore-personalize/pass-outputs-between-decisions.html "Pass outputs between decisions"). 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](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/introduction-to-decisioning-in-sitecore-personalize/managing-programmable-decisions/including-dates-in-programmable-decisions.html "Including dates in programmable decisions").
        - **Map** - Returns the entire object for the next decision to use.
3. Enter the JavaScript for the **Programmable Decision**. To automatically format and indent the JavaScript code, click ![Format JS icon](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/preetify.png).

    We recommend that you familiarize yourself with [supported](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/introduction-to-decisioning-in-sitecore-personalize/managing-programmable-decisions/supported-and-unsupported-javascript-entities/supported-javascript-functions.html "Supported JavaScript functions") and [unsupported](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/introduction-to-decisioning-in-sitecore-personalize/managing-programmable-decisions/supported-and-unsupported-javascript-entities/unsupported-javascript-functions-and-alternatives.html "Unsupported JavaScript functions and alternatives") JavaScript functions.

    You can use the [Immediately Invoked Function Expression](https://en.wikipedia.org/wiki/Immediately_invoked_function_expression)**(IIFE)**.

    > [!tip]
    > As you write, a code editor library displays with attributes and snippets that you can select from.

4. You can import one or more [JS module functions](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/js-modules.html "JS Modules"), instead of having to create the code from scratch. To do this, click ![Library icon](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_libraryIcon.png) and choose the JS modules, as shown in the following image:

    ![Importing a JS module](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_addJSmodule.png)

    > [!tip]
    > To open the JS module, hover over the name and click ![pers_openJS.png](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_openJS.png). To view a description, hover over the name and click ![pers_desc.png](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_desc.png).

    The number of imported JS modules is updated on the ![pers_jsmodulenum.png](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_jsmodulenum.png) icon. Sitecore Personalize inserts the code from the JS modules when the programmable decision compiles.

5. 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 ![CDP_webtemp_pencilicon.png](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/CDP_webtemp_pencilicon.png) 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.

        > [!note]
        > If 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.

6. 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](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/using-server-side-javascript-in-sitecore-personalize/understanding-data-limits-in-decisioning-and-conditions.html "Understanding data limits in decisioning and conditions").
7. Click the **Save** button to save your changes.