Try our conversational search powered by Generative AI!

Add a new CustomerGroup dynamically


Hi, using Commerce is there a way to add to the CustomerGroup Dynamically with code?

I can see where you can set and get a specific customer's CustomerGroup but I cant see how you can add a new CustomerGroup item via code into the CustomerGroup list.


Mar 11, 2014 12:43


This is how I did it in versions prior to 7.5, have not had to do this in 7.5 so don't know if it still works there.


var groupName = "MyNewCustomerGroup";
foreach (MetaFieldType fieldType in DataContext.Current.MetaModel.RegisteredTypes)
    if (fieldType.Name == "ContactGroup")
        if (!fieldType.EnumItems.Any(item => string.Compare(item.Name, groupName, true) == 0))
            Mediachase.BusinessFoundation.Data.Meta.Management.MetaEnum.AddItem(fieldType, groupName, fieldType.EnumItems.Last().OrderId + 1);




Edited, Mar 11, 2014 16:11

The code Vickor posted is correct and should be working, but I suggest a little change to make it more effective:

var metaFieldType = Mediachase.BusinessFoundation.Data.DataContext.Current.MetaModel.RegisteredTypes["ContactGroup"];

You now can use metaFieldType directly without loop.





Mar 12, 2014 8:03
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.