3

I'm trying to find a way to allow a user to pick from a multi-select list as part of a rule condition, but I'm not having any luck.

My exact scenario is that each user on the site needs to identify as a certain investor type, before they are allowed to proceed onto the site. Now what we want the users to be able to do is to be able to personalize components in the experience editor based on the users investor type. I'm looking to create a rule like this:

where current investor matches one of these [investorTypes,Multiselect,root=/sitecore/content/home/data/investor types,selected types]

Does anyone know if this is at all possible out of the box? Or if something similar has been done elsewhere? I think that the worst-case-scenario is to use a tree instead, and tell them to break it up into multiple conditions... but that seems like it's adding unnecessary work on the content author, when the multi-select is a concept everyone is already familiar with.

We're on Sitecore 9.0.1, if it matters.

0

2 Answers 2

4

OOTB Sitecore, this is not possible. However, you can still use the Treelist and there is no need to create different conditions. The way I use the treelist is as shown below

Rule Creation

where current investor matches one of these [AssociatedInvestor,Treelist,root=/sitecore/content/Home/Investor Types,selected types]

The below screenshot is the outcome from the Rule Creation Window

enter image description here

enter image description here

As you can see in the above screenshots, I have selected multiple items under only one condition. So, for your use case, based on the path you specified in the question (/sitecore/content/home/data/investor types), all your investor types are under that path. You just need to add your path with a Treelist type.

Now, in the code when you are implementing the condition, you will already have access to both selected value. The selected value are delimited by |.

enter image description here

So, your code will be like this for the condition

public class InvestorTypeCondition<T> : WhenCondition<T> where T : RuleContext
{
    public string AssociatedInvestor { get; set; }

    protected override bool Execute(T ruleContext)
    {
        Assert.ArgumentNotNull(ruleContext, "ruleContext");

        if (!this.AssociatedInvestor.IsNullOrEmpty())
        {
            var selectedInvestors = this.AssociatedInvestor.Split('|');
            if (selectedInvestors.Any())
            {
                foreach (var selectedInvestor in selectedInvestors)
                {
                    // YOUR LOGIC GOES HERE
                }
            }
        }

        return true;
    }
}
0

Listening to your scenario, it sounds like what you want is for the end user to identify themselves as a certain type of user and then personalize the site based on that selection.

When I talk in meetings about this exact scenario I always show https://www.airforce.com/ as an example. The user self identifies themselves as a certain type of user by selecting the a few selectors.

enter image description here

In the Sitecore world, I make those selectors call an API and set facets on the user's contact. Then I personalize the user either on a pattern card, identified by those selections. Or by a rule that reads the facet value.

The pattern card bits are OOTB.

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.