---
title: "Create a custom condition"
slug: "create-a-custom-condition"
abstract: "Create custom conditions in Sitecore Personalize to filter experiments or experiences based on real-time behavior, enhancing targeted marketing efforts."
---
# Create a custom condition

A [condition](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions.html "Conditions") allows you to filter an experience or experiment based on real-time visitor behavior.

If you're familiar with JavaScript, you can manually build a custom condition by writing your own logic. You can either modify an existing out-of-the box or custom condition, or build a new one entirely from scratch.

Users with a *User*, *Developer*, or *Admin* app role in Sitecore Cloud Portal can create custom conditions. These conditions can be created manually or with the help of the [Code Assistant](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/ai-in-personalize/code-assistant.html "Code Assistant") .

> [!note]
> If your organization also has a SitecoreAI license, you can create custom conditions in both Sitecore Personalize and the SitecoreAI Page Builder. Custom conditions created in Sitecore Personalize are also available when you specify [variables](https://doc.sitecore.com/sai/en/users/sitecoreai/specifying-variables-for-conditions.html) for conditions in SitecoreAI.

Before you start, we recommend you familiarize yourself with the following topics:

- [Types of parameters](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/create-a-custom-condition/types-of-parameters-for-conditions.html "Types of parameters for conditions"), [context parameters](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/create-a-custom-condition/context-parameters-for-conditions.html "Context parameters for conditions") and [elements](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/create-a-custom-condition/condition-elements.html "Condition elements") used in conditions.
- [Supported and unsupported JavaScript functions](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/introduction-to-decisioning-in-sitecore-personalize/managing-programmable-decisions/supported-and-unsupported-javascript-entities.html "Supported and unsupported JavaScript entities")
- [Best practices for creating custom conditions](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/best-practices-for-creating-custom-conditions.html "Best practices for creating custom conditions").

To create a custom condition manually:

1. On the navigation menu, click **Developer center** > **Conditions**.
2. Click **Create**. Alternatively, you can [duplicate and edit an existing condition](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/manage-conditions.html "Manage conditions").
3. Enter a name for the new condition and click **Create**.
4. In the code editor, click **Edit**![The edit icon](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/edit_pencil.png) and configure the JavaScript. To automatically format and indent the JavaScript code, click **Format JS** ![Format JS icon](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/preetify.png).

    We recommended that you return an object in the response body. You can [copy code](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/manage-conditions.html "Manage conditions") from another condition to help get you started.

    > [!tip]
    > The value returned in the response can be accessed from the variant API response as 'filter'.

5. Click the **Data** tab in the right pane to copy a guest data model attribute or path and paste into the JavaScript editor. Click ![Edit icon](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/edit_pencil.png) 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.

        > [!tip]
        > If there is a guest whose data you often use when configuring or testing code, click the **star** icon to bookmark the guest so you no longer have to search for them.

6. As you define input parameters in the JavaScript coding pane, the parameter names display in the **Configuration** tab.
7. Click **Save** to apply your changes. After saving your custom condition, make sure to [define the condition output](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/create-a-custom-condition.html#UUID-2998a79d-36c4-00bc-c9c1-8af9323ac87d_section-idm4549371569148833363491053178 "Define the condition output") using the appropriate parameter names.

## Define the condition output

The condition output is a combination of descriptive phrases and input parameters. This is what a user will see when they select a condition to apply to an experiment or experience, as shown below:

![Selecting a condition](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/selectCondition.png)

"The visit *has / has not* started on a page that *compares to* *page* during the current visit"

In this example, *has / has not*, *compares to*, and *page* are input parameters that the user will select values for when they apply the condition to an experiment or experience. We recommend that you phrase the condition output in a way that's similar to how you would structure a sentence.

To define the condition output:

1. In the **Configuration** tab, select the **Output** option.
2. Enter the text and the parameters in the **Configure** text box. This is the what the user will see when they apply the condition to the experiment or experience. As you type, the output displays in the **Preview** section. Valid parameters are bolded. To see the input parameter values that the user will be able to select from, click the **Input** option.

    Parameters are case-sensitive and must be wrapped in double square brackets, for example: `[[path.name]]`.

    > [!note]
    > You must include all the condition parameters in the **Configure** text box, that are defined in the JavaScript coding editor. Parameters that are defined in the JavaScript but haven't been included in the **Configure** text box have a red exclamation mark. Click ![pers_copyParam.png](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/pers_copyParam.png) to copy the parameter name and paste it into the **Configure** text box.
    >
    > Parameters that have been included in the **Configure** text box and are valid have a green checkmark.

    This image shows that the **has** input parameter is defined in the JavaScript and has been included in the **Configure** text box. The green checkmark displays to indicate the input parameter was successfully included. The **compares to** parameter and **page** parameter have red exclamation marks because although they are included in the **Configure** text box, they are not wrapped in double square brackets and have an invalid syntax. To make the syntax valid and have the green checkmark display, wrap the parameters in double square brackets.

    ![Configuring a condition](https://doc.sitecore.com/api/markdown-image/personalize/en/users/sitecore-personalize/images/condition_firstpg.png)

3. A preview of the condition output displays on the **Configuration** tab. This is useful to see how the user will view the condition when applying it to an experiment or experience. Click the **Input** option to view the parameter values that a user can select for the condition.
4. Click **Test** to [test the condition](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/test-a-condition.html "Test a condition") using guest data. We recommend testing the condition before you [publish it](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/developer-center/conditions/manage-conditions.html#UUID-04369032-3c1b-5080-c03e-3d6998089166_section-idm4582172472156833683000622423 "Publish"), to identify any errors and ensure optimal performance.