Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

How to get the datatype of metafields in Episerver 10


We have soem dynamic set of properties/metafields that we want to update from code behine.

Before updating the fields we want to check the datatype, validate the data and then update the value in the field. 

In episerver 10 , metafields are added in "Properties" property of each object (linetiem, catalogentry, orderform, ect) as a dictionary. So it only contains the name of the fields and value.

Is there a way to get the "datatype"  of the metafield. 

We had this in episerver 9 which use to work just fine

We now have this, which DOSEN"t work
This doesn't work. When the value is null for the given metafield it throws error.

May 01, 2017 17:05

Not sure if this by any means is a recommended way of doing it with the new interface based order system. But this is what I found while looking around:

if (currItem is ILineItem)
    var type = OrderContext.Current.LineItemMetaClass.MetaFields[key].DataType;

// There are many more of these but here are some examples:

You probably already know what "currItem" is so you might not need the if-clause.

Edited, May 02, 2017 11:19

That totally worked. Thank you!

Do you think this can cause a performance issue by any means?

May 02, 2017 18:51

"Do you think this can cause a performance issue by any means?"

OrderContext.Current.LineItemMetaClass is used in the constructor of the concrete LineItem class. In other words, the MetaClass-property you used before v10 was built up using that same call to OrderContext.Current.LineItemMetaClass. :)

In either case the data seems to be cached after the first time it gets picked up from the DB. I'd assume that it's safe to say that the performance hit would be negligeble or non-existant even if you keep recalling OrderContext.Current.LineItemMetaClass.

Edited, May 03, 2017 9:40

Thank you for explaining that! :) 

Great, we are good then here. 

May 03, 2017 17:39
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.