2

In Sitecore 8.2 there is a dll named Sitecore.Analytics.Automation and it contains the below properties:

public class AutomationRuleContext : RuleContext
{
    public AutomationRuleContext();

    public AutomationStateContext ContactState { get; set; }
    public bool IsBackgroundUpdater { get; set; }
    public string PageEventName { get; set; }
    public PageEventItem PageEvent { get; set; }
    public Item StateItem { get; set; }
    public CurrentInteraction Visit { get; set; }
    public Contact Contact { get; set; }
}

and implementation is used as below:

public class MyClass<T> : WhenCondition<T> where T : AutomationRuleContext

Existing project Sitecore 8.2 is using
public AutomationStateContext ContactState { get; set; }
properties in the Execute method.

The Execute method is in the WhenCondition class as below:

public abstract class WhenCondition<T> : RuleCondition<T> where T : RuleContext
{
    protected WhenCondition();

    public override void Evaluate(T ruleContext, RuleStack stack);
    protected abstract bool Execute(T ruleContext);
}

does anyone have an idea about AutomationRuleContext and WhenCondition, where it's moved in Sitecore 10.2, and how can we use them in the Sitecore 10.2 project while migration?

2

1 Answer 1

1

Sitecore Marketing Automation has been completely rewritten since 8.2.

In Sitecore 9+ you need to write conditions which implement ICondition and IContactSearchQueryFactory interfaces

E.g.

public class PreferredCinemaMatches : ICondition, IContactSearchQueryFactory
{
    public string PreferredCinema { get; set; }

   // TIP: There are other operation types in theSitecore.XConnect.Segmentation.Predicates namespace
    public StringOperationType Comparison { get; set; }

    // Evaluates condition for single contact
    public bool Evaluate(IRuleExecutionContext context)
    {
        var contact = context.Fact<Contact>();

        return Comparison.Evaluate(contact.GetFacet<CinemaDetails>(CinemaDetails.DefaultFacetKey)?.PreferredCinema, PreferredCinema)
            && contact.Interactions.Any();
    }

    // Evaluates contact in a search context
    // IMPORTANT: Use InteractionsCache() facet rather than contact.Interactions as some search providers do not provide joins.
    public Expression<Func<Contact, bool>> CreateContactSearchQuery(IContactSearchQueryContext context)
    {
        return contact => Comparison.Evaluate(contact.GetFacet<CinemaDetails>(CinemaDetails.DefaultFacetKey).PreferredCinema, PreferredCinema)
        && contact.InteractionsCache().InteractionCaches.Any();
    }
}

More information in Sitecore docs here: https://doc.sitecore.com/xp/en/developers/101/sitecore-experience-platform/create-a-custom-condition-and-segmentation-query.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.