Activity type paths

Version: 9.3

Paths are routes that a contact can take from one activity to another. The number of paths from a single activity is determined by the activity type. An activity type can define one of the following:

  • A single default path - examples include the Sitecore.Marketing.Automation.Activity.ChangeContactBehaviorProfileValue activity type.

  • True and false paths - examples include the Sitecore.Marketing.Automation.Activity.Conditional activity type.

Important

Valid activity path key names are "true", "false", and "default". Case is important and must be adhered to. You cannot define additional custom paths.

In the following example, the highlighted activity uses the Sitecore.Marketing.Automation.Activity.GoalTriggered activity type. This activity type defines true and false paths, which are reflected in the UI:

Example of marketing automation plan activity with true and false paths.

Paths are made up of:

  • An instance of the SuccessMove class within the activity type class (return new SuccessMove("true")).

  • A path item under the activity type descriptor item. The value of the Key field must match the path key defined in code.

Setting activity paths

Note

The following steps are performed by the Marketing Automation UI.

When a plan is created using the Automation Plan Definition Manager, each AutomationActivityDefinition can define one path (default) or two paths (true and false). The path keys available are determined by the activity type.

In the following example, firstActivity defines a path with the key default. This assumes that the activity type represented by the descriptor item ID {56632708-510a-46fd-995d-6a4a709e90d4} has a path with a matching key.

RequestResponse
var secondActivity = new AutomationActivityDefinition
{
    Id = Guid.NewGuid(), // ID of this instance
    ActivityTypeId = Guid.Parse("24632708-a10a-46fd-995d-6a4a709e90d4"),
};

var firstActivity = new AutomationActivityDefinition
{
    Id = Guid.NewGuid(), // ID of this instance
    ActivityTypeId = Guid.Parse("56632708-510a-46fd-995d-6a4a709e90d4"),
    Paths =
    {
        { "default", secondActivity.Id }
    }
};

If a contact is evaluated within firstActivity and the underlying activity type returns newSuccessMove("default"), the contact is moved along the default path to secondActivity.

Note

Technically, you do not need a path item in order to use a particular path key. If a path key exists in the activity type class, the Automation Plan Definition Manager can use it. However, the Marketing Automation UI relies on every path being represented by an item.

A path is only considered a legal path within a plan if it is declared in the Paths property of an AutomationActivityDefinition object. For example, the following AutomationActivityDefinition defines a single path named default:

RequestResponse
var firstActivity = new AutomationActivityDefinition
{
    Id = Guid.NewGuid(), // ID of this instance
    ActivityTypeId = Guid.Parse("18b8c9e0-dc4e-b757-4f07-ba91f7c60ea7"),
    Paths =
    {
        { "default", secondActivity.Id }
    }
};

When you save a plan definition item in Sitecore, Sitecore represents this data as JSON in the Plan Data field:

Plan data shown from the Content Editor

The activity type class represented by the {18b8c9e0-dc4e-b757-4f07-ba91f7c60ea7} ID might have logic that incorrectly returns the following path:

RequestResponse
return new SuccessMove("true");

Since the plan definition does not include a path with the key true, the path is not legal. If this happens, a failure is returned instead:

RequestResponse
return new Failure();

This scenario might occur if you fail to create the correct path items for an activity type.

Get all activity type paths

Use the Activity Type Descriptor Locator API to retrieve all available paths for a particular activity type. The following example demonstrates how to get the key and name of every parameter for a particular activity type:

RequestResponse
using System;
using Sitecore.Xdb.MarketingAutomation.Locators.AutomationPlans;
using Sitecore.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using System.Globalization;

namespace Documentation.Examples
{
    public class Locators
    {
        public void LocatorsExample()
        {
            var locatorService = ServiceLocator.ServiceProvider.GetService<IActivityDescriptorLocator>();

            var activityTypeDescriptorId = Guid.Parse("{56632708-510a-46fd-995d-6a4a709e90d4}");

            var descriptor = locatorService.GetDescriptor(activityTypeDescriptorId, CultureInfo.InvariantCulture);

            foreach (var path in descriptor.Paths)
            {
                var key = path.Key; // Path key - e.g. default
                var name = path.Name; // Human-readable path name - e.g. Default Path
            }
        }
    }
}

Do you have some feedback for us?

If you have suggestions for improving this article,