openForm (JavaScript API Reference) for Dynamics 365 Channel Integration Framework 2.0

Opens an entity form or a quick create form.

Syntax

Microsoft.CIFramework.openForm(entityFormOptions,formParameters).then(successCallback,errorCallback);

Parameters

                             
NameTypeRequired Description
entityFormOptionsObjectYes 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".
    • on: The navigation bar is displayed. This is the default behavior if the navBar parameter is not used.
    • off: The navigation bar is not displayed. People can navigate using other user interface elements or the back and forward buttons.
    • entity: On an entity form, only the navigation options for related entities are available. After navigating to a related entity, a back button is displayed in the navigation bar to allow returning to the original record.
  • openInNewWindow: (Optional) Boolean. Indicates whether to display form in a new window.
  • windowPosition: (Optional) Number. Specify one of the following values for the window position of the form on the screen:
    • 1:center
    • 2:side
  • processId: (Optional) String. ID of the business process to be displayed on the form.
  • processInstanceId: (Optional) String. ID of the business process instance to be displayed on the form.
  • relationship: (Optional) Object. Define a relationship object to display the related records on the form. The object has the following attributes.
      Name     Type     Description attributeName String Name of the attribute used for relationship. name String Name of the relationship. navigationPropertyName String Name of the navigation property for this relationship. relationshipType Number Relationship type. Specify one of the following values:
  • 0:OneToMany
  • 1:ManyToMany
roleType Number Role type in relationship. Specify one of the following values:
  • 1:Referencing
  • 2:AssociationEntity
  • selectedStageId: (Optional) String. ID of the selected stage in business process instance.
  • useQuickCreateForm: (Optional) Boolean. Indicates whether to open a quick create form. If you do not specify this, by default false is passed.
  • width: (Optional) Number. Width of the form window to be displayed in pixels.
  • formParameters Object No A dictionary object that passes extra parameters to the form. Invalid parameters will cause an error.

    For information about passing parameters to a form, see Set field values using parameters passed to a form and Configure a form to accept custom querystring parameters successCallback Function No A function to execute when operation succeeds. errorCallback Function No A function to execute when the operation fails.

    Returns

    On success, returns a promise object containing string.

    Remarks

    You must use this method to open entity or quick create forms instead of the deprecated Xrm.Utility.openEntityForm and Xrm.Utility.openQuickCreate methods.

    Examples

    The following sample code opens a new incident form with pre-populated values for certain fields like contact Id and description.

    var id = "5af02e2a-d0d1-e811-8158-000d3af97055"
    var title = "Sample Case Form"
    var entityFormOptions = {};
        entityFormOptions["entityName"] = "incident";
        
    var formParameters = {};
        //pre-populate some fields based on the context
        formParameters["title"] = title;
        formParameters["customerid"] = id;
        formParameters["customeridtype"] = "contact";
        formParameters["caseorigincode"] = 1;
        formParameters["description"] = "Opened the form with pre-populated details like title, contact id, and description.";
    
    //Open the form
    Microsoft.CIFramework.openForm(JSON.stringify(entityFormOptions), JSON.stringify(formParameters)).then(
          function (success) {
            console.log(success);
        },
        function (error) {
            console.log(error);
        }
      );