Created
March 5, 2015 10:52
-
-
Save davidknipe/3ff4fc7a22fb0b2c30c6 to your computer and use it in GitHub Desktop.
Create an EPiServer Commerce Metafield programmatically and add it to a Metaclass in Business Foundation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Programmatically create a new MetaField on the Contact MetaClass <seealso href="http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/8/Business-Foundation/Business-Meta-Model/MetaField-class/"/> | |
| /// </summary> | |
| private void setupMetaField() | |
| { | |
| MetaClassManager metaModel = DataContext.Current.MetaModel; | |
| foreach (MetaClass mc in metaModel.MetaClasses) | |
| { | |
| if (mc.Name == "Contact") | |
| { | |
| //Delete if needed | |
| //mc.DeleteMetaField(mc.Fields["DOB"]); | |
| string fieldName = "DOB"; | |
| if (mc.Fields[fieldName] == null) | |
| { | |
| AttributeCollection attr = new AttributeCollection(); | |
| MetaField newMetafield = mc.CreateMetaField( | |
| fieldName, | |
| "Date of Birth", | |
| MetaFieldType.Date, | |
| true, | |
| string.Empty, | |
| attr); | |
| } | |
| break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment