Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
In situations like this - when you try to mimic a UI behavior - it helps to fire up the ole reflector =) In your case, I'd take a look in Mediachase.ConsoleManager.dll, starting with MetaFieldEditControl.SaveButton_Click and taking it from there. Good luck, and let us know your findings!
Nevermind.
When I use MetaEnum.AddItem(metaFieldType, value, orderId) instead of adding the items to the EnumItems it works.
Hello,
As part of a scheduled job I want to create a new multi-value MetaField of type Dictionary items and to create the related dictionary items. The issue is the MetaEnumItems are not being created in the mcmd_MetaEnum and mcmd_SelectedEnumValue tables.
I am missing something because they are getting persisted somewhere but I am not sure where as I can retrieve them even after a recycle of IIS.
This is what I am using to create my enum and items:
public static bool AddEnumMetaField(string metaClassName, string name, string friendlyName, string enumName, bool isMultiValue) { var metaClass = DataContext.Current.GetMetaClass(metaClassName); if (metaClass != null) { if (metaClass.Fields[name] == null) { MetaFieldType newEnum = DataContext.Current.MetaModel.RegisteredTypes.Cast().Where(type => type.McDataType == McDataType.Enum && type.Name == enumName).FirstOrDefault();
if (newEnum == null)
{
newEnum = MetaEnum.Create(enumName, enumName, isMultiValue);
newEnum.EnumItems = new Mediachase.BusinessFoundation.Data.Meta.MetaEnumItem[]
{
new Mediachase.BusinessFoundation.Data.Meta.MetaEnumItem() { AccessLevel = AccessLevel.System, Handle = 1, Name = "X1", OrderId = 1, Owner = "System"},
new Mediachase.BusinessFoundation.Data.Meta.MetaEnumItem() { AccessLevel = AccessLevel.System, Handle = 2, Name = "X2", OrderId = 2, Owner = "System"},
new Mediachase.BusinessFoundation.Data.Meta.MetaEnumItem() { AccessLevel = AccessLevel.System, Handle = 3, Name = "X3", OrderId = 3, Owner = "System"},
new Mediachase.BusinessFoundation.Data.Meta.MetaEnumItem() { AccessLevel = AccessLevel.System, Handle = 4, Name = "X4", OrderId = 4, Owner = "System"},
new Mediachase.BusinessFoundation.Data.Meta.MetaEnumItem() { AccessLevel = AccessLevel.System, Handle = 5, Name = "X5", OrderId = 5, Owner = "System"}
};
}
AttributeCollection attr = new AttributeCollection();
attr.Add(McDataTypeAttribute.EnumEditable, true);
metaClass.CreateMetaField(name, friendlyName, enumName, true, null, attr);
metaClass.Fields[name].AccessLevel = AccessLevel.Development;
metaClass.Fields[name].Owner = "Development";
return true;
}
}
return false;
}
public static bool AddMetaField(MetaClass metaClass, string name, string friendlyName, string typeName) { if (metaClass.Fields[name] == null) { metaClass.CreateMetaField(name, friendlyName, typeName, null); metaClass.Fields[name].AccessLevel = AccessLevel.Development; metaClass.Fields[name].Owner = "Development"; return true; } return false; }
I appreciate any help!
Note: I believe the field is being created correctly as if I manually add entries in CommerceManager then I can use them without issue. I believe the issue is in how I am creating the enum entries.