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

> [!important]
> You can create custom conditions in both SitecoreAI and [Sitecore Personalize](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/create-a-custom-condition.html). To create custom conditions in Sitecore Personalize, your organization must have a standalone Sitecore Personalize license.

SitecoreAI comes with a set of out-of-the-box [conditions](https://doc.sitecore.com/sai/en/users/sitecoreai/personalize/specifying-variables-for-conditions.html "Specifying variables for conditions") you can use to build audiences. But if your personalization logic is not covered by out-of-the-box conditions and you're familiar with JavaScript, you can manually build a custom condition. Custom conditions enable sophisticated, reusable personalization logic tailored to your specific requirements, while maintaining flexibility for unique business needs. Combined with the AI Code Assistant and comprehensive testing tools, even complex conditions remain manageable and maintainable.

Custom conditions are server-side JavaScript expressions that evaluate visitor profiles:·

- Any truthy return value results in content being shown to the visitor.
- Falsy values prevent the content from displaying.

Users with a *User*, *Developer*, or *Admin* app role in SitecoreAI can create custom conditions. You can either modify an existing out-of-the box or custom condition, or build a new one entirely from scratch. These conditions can be created manually or with the help of the AI [Code Assistant](https://doc.sitecore.com/sai/en/users/sitecoreai/personalize/create-a-custom-condition/create-a-condition-with-the-code-assistant.html "Create a condition with the Code Assistant").

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

- [Types of parameters](https://doc.sitecore.com/sai/en/users/sitecoreai/personalize/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/en/context-parameters-for-conditions.html) and [elements](https://doc.sitecore.com/sai/en/users/sitecoreai/personalize/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/en/supported-and-unsupported-javascript-entities.html)
- [Best practices for creating custom conditions](https://doc.sitecore.com/personalize/en/users/sitecore-personalize/en/best-practices-for-creating-custom-conditions.html).

To create a custom condition manually:

1. In the Page builder **Personalize** mode, in the left-hand panel, click **Create variant**.
2. Enter a name for the page variant, then click **Next**.
3. In the **Create your audience** dialog, in the **Conditions** right-hand panel, click **Create**.
4. Enter a name for the new condition.
5. In the code editor, edit the JavaScript.

    We recommended that you return an object in the response body. You can copy the code from another custom condition to help get you started.

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

6. As you define input parameters in the JavaScript coding pane, the parameter names display in the **Output** tab of the right-hand panel.
7. Click **Save** to apply your changes. After saving your custom condition, make sure to [define the condition output](https://doc.sitecore.com/sai/en/users/sitecoreai/personalize/create-a-custom-condition.html#define-the-condition-output "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/sai/en/users/sitecoreai/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 right-hand panel, select the **Output** tab.
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 :mdiFileDocumentMultipleOutline: 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/sai/en/users/sitecoreai/images/condition_firstpg.png)

3. A preview of the condition output displays on the **Output** 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/sai/en/users/sitecoreai/personalize/create-a-custom-condition/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/en/manage-conditions.html#UUID-04369032-3c1b-5080-c03e-3d6998089166_section-idm4582172472156833683000622423), to identify any errors and ensure optimal performance.