There's already a role criterion in the https://world.episerver.com/add-ons/visitor-group-criteria-pack/ that can be used. You can define multiple by just adding it multiple times in the Visitor Group and setting the match to Any
However if you want to build your own I'd follow https://world.episerver.com/documentation/developer-guides/CMS/personalization/developing-custom-visitor-group-criteria/ and decompile the code for the TimeOfDayCriterion and how it's built as it has a multi picker checkbox control.
I could live with the dijit MultiSelect, but what would be the correct property type for the Groups property in that case? I just can't figure it out....
I've found that the only property type that works i object[], don't ask me why string[] in't good enough (string[] is what dijit sends back to the backend):
public class UserGroupsCriterionModel : CriterionModelBase
{
[DojoWidget(WidgetType = "dijit.form.MultiSelect", SelectionFactoryType = typeof(UserGroupSelectionFactory))]
public object[] Groups { get; set; }
public override ICriterionModel Copy()
{
return base.ShallowCopy();
}
}
One other thing to remember is that criterions work differently from normal Episerver page and block classes - if you've added a property to a class and used it, you can't change the property type! I've had to actually rename the model class several times to get it to work when I changed the type. Now I only wish there was a multiselect checkbox list dijit widget I could use :)
This question is similar to https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2021/2/multiple-string-values-in-custom-visitor-group-criterion/ (and funny it was posted just before I posted this), but in my case I'm creating a Criterion for selecting Episerver User Groups / Roles and I have two problems:
With the setup below, I get a "Failed to convert item" error when I try to save it in episerver: