November Happy Hour will be moved to Thursday December 5th.

MetaDataPlus - Create MetaField Programmatically

Vote:
 

Hi, 

We're currently on version (8.11) of EPiServer Commerce.

What's the recommended way to create a meta field for a MetaDataPlus MetaClass in EPiServer Commerce? We've got a few custom fields that we'd like to add onto the OrderForm Metaclass. Of course I know how to do this through Commerce Manager but we'd like to set up any custom metafields in an initialisation module so that an admin doesn't need to set everything up manually. 

I've been unable to find any real solid examples online. 

In the past, this is how I've done it, but it feels a bit hacky and I've noticed there's a deprecated note next to the MetaField.Create method.

1. Check the Metafield doesn't already exist. 

2. Create Metafield using Mediachase.MetaDataPlus.Configurator.MetaField.Create

3. Associate with MetaClass using Mediachase.MetaDataPlus.Configurator.MetaClass.AddField

Is there a recommended way to do this or EPi simply suggests to only do it manually? 

Thanks

#133711
Sep 09, 2015 9:13
Vote:
 

Hi,

Your approach looks good - we use it as well. Only one note is there is a newer version of MetaField.Create you should use. The old one has a parameter named "saveHistory" - which is no longer used - was marked as obsolete. Use this instead:

public static MetaField Create(
MetaDataContext context,
string metaNamespace,
string name,
string friendlyName,
string description,
MetaDataType dataType,
int length,
bool allowNulls,
bool multiLanguageValue,
bool allowSearch,
bool isEncrypted)

Regards,

/Q

#133715
Sep 09, 2015 10:58
Vote:
 

Hi Quan,

Great thanks. We'll take that approach. And I see, the deprecated note was only for the overload with saveHistory.

Thanks again!

#133746
Sep 10, 2015 0:57
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.