Skip to main content

How to benefit from adx Entity Form subgrid, lookup and other OOB features in CrmEntityFormView control.


What are Entity Form benefits?

    Adxstudio portal has managed forms  and  data driven configurations like Entity From, Entity List etc.
    Data driven configuration reflect crm forms, form tabs, views and have only front end javascript option for developers.
    Managed forms allows to developer add CrmEntityFormView control that reflects a selected crm form or form tab and provides a few custom server side events those can be consumed as well as regular aspx events (Pre Init, Init, Load etc). 
      One of the features of data driven configuration is EntityFormMetadata. This metadata can be configured for attributes, subgrids, lookups, geo attributes.  And CrmEntityFormView lacks those features. It means developer cannot control the way lookup will be rendered in the form, which buttons will be added to grid and other OOB Entity Form Metadata benefits.


How can developer get the Entity Form Metadata benefits in CrmEntityFormView control?

Crm configuration first:
     - In the entity create a form or form tab you want to reflect in the control.
     - Create an Entity From  configuration and associate it with created form by name.
     - Define Entity Form Metadata for desirable attributes.

Portal web site:
       - Create a content aspx page in the portal tree using one of master pages. I recommend always create a separate folder under Areas. This way keeps your solution clear, updateable and maintainable.  Look to  managed forms for Adx best practices.
      - Add CrmEntityFormView control to the form.

Something like this:

<adx:CrmDataSource ID="WebFormDataSource" runat="server" CrmDataContextName="<%$ SiteSetting: Language Code %>" />
    <asp:Panel ID="ContactWebForm" CssClass="crmEntityFormView" runat="server" Visible="true">
        <adx:CrmEntityFormView runat="server" ID="FormView"
            EntityName="entity name"
            FormName="Form Name"
            TabName="Tab Name"
            OnItemInserted="OnItemInserted"
            OnItemInserting="OnItemInserting"
            RecommendedFieldsRequired="True"
            ShowUnsupportedFields="False"
            DataSourceID="WebFormDataSource"
            ToolTipEnabled="False"
            Mode="Insert"
            ClientIDMode="Static"
            ValidationGroup="ValidationGroup"
            LanguageCode="<%$ SiteSetting: Language Code, 0 %>"
            ContextName="<%$ SiteSetting: Language Code %>">
            <InsertItemTemplate></InsertItemTemplate>
        </adx:CrmEntityFormView>

 - Add the follow method to the code behind:
 

/// <summary>
/// Returns the Entity Form Metadata by form name.
/// </summary>
/// <param name="entityFormName">Name of the entity form.</param>
/// <returns>Form Meta Data Collection</returns>
protected IQueryable<Entity> GetEntityFormMetaData(string entityFormName)
   {
    if (string.IsNullOrEmpty(entityFormName)) return null; 
    Entity entityForm = ServiceContext.CreateQuery("adx_entityform")
                .Where(a => a.GetAttributeValue<string>("adx_name") ==   entityFormName).FirstOrDefault(); 
     if (entityForm != null)
     {
      //find all metadata entities for this Entity Form                  IQueryable<Entity> formMetadataCollection = ServiceContext.CreateQuery("adx_entityformmetadata").Where(a => a.GetAttributeValue<EntityReference>("adx_entityform").Id == entityForm.Id);
      if (formMetadataCollection != null)
        {
                    return formMetadataCollection;
         } 
     }           
 return null;
 }

- Add the follow code to the Page_Init:
string formName = ServiceContext.GetSnippetValueByName(Website, "FormName");
  var metadataFormCollection = GetEntityFormMetaData(formName);
  if (metadataFormCollection != null)
   {
      // attach metadata collection to CrmEntityFormView
       FormView.WebFormMetadata = metadataFormCollection;
    }
- Have an appropriate snippet in crm per language or use hardcoded value for “FormName”


This is it. You have both metadata benefits and custom events on backend in the same time.

A disclaimer:

Please mind that WebFormMetadata attribute of CrmEntityFormView control is not documented by Adx. I couldn’t find any. I don’t know if the way is supported by Adx and if Adx(now Microsoft) is going to support it in the future.

Comments

Most popular

Dynamics 365 online and Adx portal on-premise. Are they compatible?

Adxstudio Portal how to: Incremental (Sequential) Deployment and backup. Part I

Custom plugin exception output for crm form