Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Introduction to Sitecore Personalize
Managing accounts and system settings
Identifying guests
Introduction to experiments
Introduction to experiences
Decisioning
View dashboards
Developer Center
Connecting to an external system
Using client-side JavaScript
Using server-side JavaScript
AI in Personalize
Glossary
  • Sitecore Personalize
  • Developer Center
  • Conditions
  • Test a condition

Test a condition

Sitecore Personalize enables you to test a condition by running it against a selected guest.

We recommend testing the condition before you publish it, to identify any errors and ensure optimal performance. After changing the code, re-test the condition with the same guest to check the results.

For more advanced use cases that require passing in headers and parameters in the request, you can test an advanced condition.

When you test a condition, Sitecore Personalize tests the JavaScript on the server-side. This ensures that the JavaScript is validated within the context it will be executed in.

Team members with a User, Developer, or Admin role in Sitecore Cloud Portal can test a condition.

To test a condition:

  1. Open the condition and click Test.

    Testing a condition
  2. In the Test Condition dialog, you can test against the default guest's attributes, or click in the search box and choose Recent to select from a list of recently active guests or Bookmarks to select from a list of bookmarked guests. The system selects a guest who was recently active. 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.

  3. To temporarily modify the guest data (this is only temporary and does not change any attributes associated with the guest), edit the JSON in the code editor.

  4. Click Test. The condition runs as it would in production, against the data of the selected guest. The output of the condition displays on the Response tab.

Add guest parameters

You can configure the guest parameters to allow you to view them in the test's response. To achieve this, you must include a function in your condition that calls the guest context.

To add guest parameters to a condition:

  1. In the code editor, include this JavaScript in the code editor to call the guest context, as shown here:

    RequestResponse
    (function () {
            return { guest: guest };
    })();
  2. Click the Condition parameters option to enter the values.

  3. Click Test. The output of the condition, including the guest parameters display on the Response tab.

Add a point of sale parameter

You can configure the Point of Sale parameter to allow you to view it in the test's response. To achieve this, you must include a function in your condition that calls the request context.

To add a point of sale parameter to a condition:

  1. In the code editor, include this JavaScript in the code editor to call to call the request context, as shown here:

    RequestResponse
    (function () {
            return { request: request };
    })();
  2. Click the Experience request option and select the point of sale from the drop-down list.

  3. Click Test. The output of the condition, including the Point of Sale parameter display on the Response tab

Add tenant parameters

You can configure the tenant parameters to allow you to view them in the test's response. To achieve this, you must include a function in your condition to call the tenant context.

To add tenant parameters to a condition:

  1. In the code editor, include this JavaScript in the code editor to call the tenant context, as shown here:

    RequestResponse
    (function () {
            return { tenant: tenant };
    })();

    For example, the out-of-the-box Visit date of month (organization time zone) condition includes the tenant.configurations.timezone parameter in the JavaScript, as shown here:

    RequestResponse
    (function () {
        load("classpath:moment.js");
        load("classpath:moment-timezone.js");
        var returnValue = false;
        var comparison = false;
        var comparator = "[[is | enum(is, is not) | is | { required: true }]]";
        var operatorValue = "[[compares to | enum(is equal to,is greater than,is less than,is greater than or equal to,is less than or equal to,is between) | | { required: true, placeholder: compares to} ]]";
        var dayOfMonth = Number("[[number | number | | { required: true, min: 0, max: 31, placeholder: 0 }]]");
        var dayOfMonth2 = Number("[[until day | number | | { required: true, min: 0, max: 31, placeholder: 0 }]]");
        var tenantTimezone = "";
        if (tenant && tenant.configurations && tenant.configurations.timeZone) {
            tenantTimezone = tenant.configurations.timeZone;
        }
        var tenantDate = moment.tz(tenantTimezone).date();
        
        if (operatorValue === 'is between') {
                comparison = tenantDate >= dayOfMonth && tenantDate <= dayOfMonth2;
        } else {
            if (operatorValue === 'is equal to') {
               comparison = tenantDate === dayOfMonth; 
            } else if (operatorValue === 'is greater than') {
                comparison = tenantDate > dayOfMonth;
            } else if (operatorValue === 'is less than') {
                comparison = tenantDate < dayOfMonth;
            } else if (operatorValue === 'is greater than or equal to') {
                comparison = tenantDate >= dayOfMonth;
            } else if (operatorValue === 'is less than or equal to') {
                comparison = tenantDate <= dayOfMonth;
            }
        }
            
        if (comparator === "is") {
            returnValue = comparison;
        } else {
            returnValue = !comparison;
        }
        return returnValue;
    })();
  2. Click the Condition parameters option to enter values.

  3. Click Test. The output of the condition, including the tenant parameters display on the Response tab

Add a print statement

To help debug a condition or understand its flow, you can include print() statements in your condition. These allow you to view the condition output in the response, up until the point the code throws an error.

To add a print statement to a condition:

  1. In the code editor, include a JavaScript for the print() statement. For example:

    RequestResponse
    (function () {
            print("first log");
            print("second log");
            return true;
    })();
  2. Click Test. The output of the condition displays on the Response tab.

  3. To view the logs from the print() statements, click Logs as shown below:

    Print statement logs in the Response tab.

Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2026 Sitecore