Try our conversational search powered by Generative AI!

Loading...
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

A MetaField object represent a meta class field. Fields represent information that an object contains. Fields are like variables because they can be directly read or set. For example, if you have an object named "Car", you could store its color in a field named "Color".

When creating and deleting meta fields, remember that a meta model can only be modified in Design mode. Refer to the MetaClassManager Class section for more information.

From the MetaField object you can get complete information about fields:

  • Name
  • Meta Type
  • Default Value
  • Formula for auto-calculated columns
  • Is Nullable
  • Is ReadOnly
  • Is Primary Key
Business Foundation uses a meta field installer assigned to the meta type, to add meta fields to meta classes.

Getting a meta field collection

The collection of meta fields is available from the MetaClass.Fields property, and it will return a MetaFieldCollection object.

Example: The following example writes all fields to trace

C#
foreach (MetaField field in mc.Fields)
{
 System.Diagnostics.Trace.WriteLine(field.Name);
}

Creating a meta field

Call the CreateMetaField method of the MetaClass class, passing name, friendly name, type, is nullable flag, default value and attributes to create a new meta field. The attributes depends on the meta type.

Example: Create a new Guid meta field

C#
public MetaField CreateGuid(string name, string friendlyName, bool isNullable)
{
if (name == null)
throw new ArgumentNullException("name");
if (friendlyName == null)
throw new ArgumentNullException("friendlyName");
AttributeCollection attr = new AttributeCollection();
string defaultValue = isNullable ? string.Empty : "newid()";
MetaField retVal = this.MetaClass.CreateMetaField(name, friendlyName, MetaFieldType.Guid, isNullable, defaultValue, attr);
return retVal;
}

Deleting a meta field

Call the CreateMetaField method of the MetaClass class, passing name, friendly name, type, is nullable flag, default value and attributes to create a new meta field. The attributes depends on the meta type.

Example: Create a new Guid meta field

C#
public MetaField CreateGuid(string name, string friendlyName, bool isNullable)
{
if (name == null)
throw new ArgumentNullException("name");
if (friendlyName == null)
throw new ArgumentNullException("friendlyName");
AttributeCollection attr = new AttributeCollection();
string defaultValue = isNullable ? string.Empty : "newid()";
MetaField retVal = this.MetaClass.CreateMetaField(name, friendlyName, MetaFieldType.Guid, isNullable, defaultValue, attr);
return retVal;
}

Deleting a meta field

Call the DeleteMetaField method of the MetaClass class, passing the meta field object to, delete a field from the meta class.

Example: Find column by name and drop

C#
// Delete field
mc. DeleteMetaField(mc.Fields\["Book Title"]);
Do you find this information helpful? Please log in to provide feedback.

Last updated: Mar 31, 2014

Recommended reading