November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi Ian,
We ended up doing this manually in Commerce Manager in all environments.
Administration -> System Settings -> Business Foundation -> Contact -> Forms tab -> View Form.
Lars
After adding the metafields to the metaclass you can add the field to the desired form by code as well.
The function to use is:
FormController.AddMetaPrimitive(string metaClassName, string formName, string fieldName)
(Mediachase.BusinessFoundation.MetaForm.FormController)
The Form names are:
Edit Form -> [MC_BaseForm]
Short Info Form -> [MC_ShortViewForm]
View Form -> [MC_GeneralViewForm]
If you wish to do it in a more controlled manner, for example deciding where in the form to put the field, its span, border, label etc you can use the FormDocument instead.
var forms = SqlFormDocumentManager.GetFormDocuments(className) will load all forms for a meta class
var theForm = forms.FirstOrDefault(x => x.DocumentType == "[MC_BaseForm]")
DocumentType can be used to determine which form you wish to edit, and the form object you end up with will give you access to all rows, columns, sections, controls and items.
SqlFormDocumentManager.Save(theForm) will save your changes.
So to add a meta field to a form you'd need to do something like this.
var newField = new FormItem() { RowIndex = 0, // Will be placed first CellIndex = 1, RowSpan = 1, ColSpan = 1, BorderType = 0, ShowLabel = true, LabelWidth = "120px", Uid = Guid.NewGuid().ToString("N") }; newField.Labels.Add(new FormLabel("My label:", "en")); // Add a label newField.Control = new FormControl("MetaPrimitive") // Add the control for the field { Source = "SourceFieldName", ReadOnly = false, Uid = Guid.NewGuid().ToString("N") }; theForm.FormTable.Rows[0].Cells[0].Sections[0].Control.Items.Add(newField); // Adding the field to the first section, first cell, first row SqlFormDocumentManager.Save(theForm);
Just a note:
var forms = SqlFormDocumentManager.GetFormDocuments(className)
will return 0 elements, if you still have default form and only starts returning it if there are some modifications in form(at least for Organization in epi comm 13.19)
Hello,
We recently had a support case related to this area. The following steps will be resolved it.
private void CreateMetaField(string metaClassName, string metaFieldName, string friendlyName,
bool isNullable = true, int maxLength = 255, bool isUnique = false)
{
var metaClass = DataContext.Current.GetMetaClass(metaClassName);
if (metaClass == null)
{
return;
}
var fieldExists = metaClass.Fields.Contains(metaFieldName);
if (fieldExists)
{
return;
}
using (var metaFieldBuilder = new MetaFieldBuilder(metaClass))
{
metaFieldBuilder.MetaClass.AccessLevel = AccessLevel.Customization;
metaFieldBuilder.CreateText(metaFieldName, friendlyName, isNullable, maxLength, isUnique);
metaFieldBuilder.SaveChanges();
}
//Add metafield to form.
AddMetaFieldToForms(metaClassName, metaFieldName);
}
private static void AddMetaFieldToForms(string metaClassName, string metaFieldName)
{
string[] formNames = { FormController.BaseFormType, FormController.GeneralViewFormType, FormController.ShortViewFormType };
foreach (var formName in formNames)
{
FormController.AddMetaPrimitive(metaClassName, formName, metaFieldName);
}
}
Then you call to CreateMetaField() method where you want like this:
//Add custom meta field to contact form programmatically.
CreateMetaField(ContactEntity.ClassName, "ContactTest_Name", "ContactTest_FriendlyName");
The new control with labeled "ContactTest_FriendlyName" will be showed in "Contact" form in CommerceManager.
Giang.Tran
In our project we've added custom meta fields to the Business Foundation contact object.
We initialize the field in an initialization module:
Then we get and set the property through CustomerContact.Properties:
This works fine. The problem is that the custom property doesn't show up on the Contact Management page in Commerce Manager, neither in the information tab or the edit form. I've seen the "Add field to"-checkboxes in Business Foundation in the Administration tab, but i would like to do this in code. Is it possible to do that?
Thanks!