Search code examples
javascriptdynamics-crmdynamics-crm-onlinedynamics-crm-365

Xrm.Navigation.openForm not honouring formid


I'm trying to follow the examples found here that explain how to use Xrm.Navigation.openForm method to open a CRM form for a new entity.

My target entity has multiple forms and I'm trying to specify the form ID in the entityFormOptions object as described in the link above. I've copied the relevant text here (with the relevant line in bold):

entityFormOptions

Entity form options for opening the form. The object contains the following attributes:

  • cmdbar: (Optional) Boolean. Indicates whether to display the command bar. If you do not specify this parameter, the command bar is displayed by default.
  • createFromEntity: (Optional) Lookup. Designates a record that will provide default values based on mapped attribute values. The lookup object has the following String properties: entityType, id, and name (optional).
  • entityId: (Optional) String. ID of the entity record to display the form for.
  • entityName: (Optional) String. Logical name of the entity to display the form for.
  • formId: (Optional) String. ID of the form instance to be displayed.
  • height: (Optional) Number. Height of the form window to be displayed in pixels.
  • navBar: (Optional) String. Controls whether the navigation bar is displayed and whether application navigation is available using the areas and subareas defined in the sitemap. Valid values are: "on", "off", or "entity".

However this doesn't seem to work for me. The ID of my form is 375DE297-C0AF-4711-A811-5F1663FAE5DA

Here's my code:

var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
entityFormOptions["formId"] = "375DE297-C0AF-4711-A811-5F1663FAE5DA";
Xrm.Navigation.openForm(entityFormOptions);

The new entity form opens; however it uses the default form, not the specified form.

I am running as a System Administrator and I have confirmed that I have access to all the forms for the specified entity so I don't think it is a form-security issue.

Has anyone tried this method of opening forms in Dynamics 365?


Solution

  • That's looks like mistake in docs or bug in Dynamics.

    Previous implementation (v8 and before) took formid in parameters object: https://msdn.microsoft.com/en-us/library/jj602956.aspx#openEntityForm

    Although current documentation states that formId must be set in entityFormOptions it isn't actually honoured. But it is honoured when you put it to good old formParameters.

    Thus this does the trick:

    var entityFormOptions = {};
    entityFormOptions["entityName"] = "contact";
    var formParameters = {};
    formParameters ["formid"] = "375DE297-C0AF-4711-A811-5F1663FAE5DA";
    Xrm.Navigation.openForm(entityFormOptions, formParameters);
    

    P.S. Note that lowercase "formid".