openForm (Client API reference)
Opens an entity form or a quick create form.
Note
To open a main form as a dialog, use the navigateTo method instead. More information: Open main form in a dialog using client API
Syntax
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(successCallback, errorCallback);
Parameters
Name | Type | Required | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
entityFormOptions | Object | Yes | Form options for opening the form. The object contains the following values:
| ||||||||||||||||||
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 column values using parameters passed to a form and Configure a form to accept custom querystring parameters |
||||||||||||||||||
successCallback | Function | No | A function to execute when the record is saved in the quick create form.
This function is passed an object as a parameter. The object has a savedEntityReference array with the following properties to identify the record(s) displayed or created:
NOTE:
|
||||||||||||||||||
errorCallback | Function | No | A function to execute when the operation fails. |
Remarks
You must use this method to open table or quick create forms instead of the deprecated Xrm.Utility.openEntityForm and Xrm.Utility.openQuickCreate methods.
Use setActiveProcess to display a particular business process and setActiveProcessInstance to display a particular business process instance on the form.
Examples
Example 1: Open a form for existing record
The following sample code opens a contact form to display an existing contact record:
var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
entityFormOptions["entityId"] = "8DA6E5B9-88DF-E311-B8E5-6C3BE5A8B200";
// Open the form.
Xrm.Navigation.openForm(entityFormOptions).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
Example 2: Open a form for new record
The following sample code opens a contact form with some pre-populated values to create a new record:
var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
// Set default values for the Contact form
var formParameters = {};
formParameters["firstname"] = "Sample";
formParameters["lastname"] = "Contact";
formParameters["fullname"] = "Sample Contact";
formParameters["emailaddress1"] = "contact@adventure-works.com";
formParameters["jobtitle"] = "Sr. Marketing Manager";
formParameters["donotemail"] = "1";
formParameters["description"] = "Default values for this record were set programmatically.";
// Set lookup column
formParameters["preferredsystemuserid"] = "3493e403-fc0c-eb11-a813-002248e258e0"; // ID of the user.
formParameters["preferredsystemuseridname"] = "Admin user"; // Name of the user.
// End of set lookup column
// Open the form.
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
Example 3: Open a form for new record (complex lookup)
The following sample code opens a activity form with some pre-populated values (including a complex lookup) to create a new record:
var entityFormOptions = {};
entityFormOptions["entityName"] = "email";
// Set default values for the Contact form
var formParameters = {};
formParameters["subject"] = "Sample";
formParameters["description"] = "Default values for this record were set programmatically.";
// Set lookup column
formParameters["regardingobjectid"] = "3493e403-fc0c-eb11-a813-002248e258e0"; // ID of the user.
formParameters["regardingobjectidname"] = "Admin user"; // Name of the user.
formParameters["regardingobjectidtype"] = "systemuser"; // Table name.
// End of set lookup column
// Open the form.
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
Example 4: Open a quick create form
The following sample code opens a quick create contact form with some pre-populated values:
var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
entityFormOptions["useQuickCreateForm"] = true;
// Set default values for the Contact form
var formParameters = {};
formParameters["firstname"] = "Sample";
formParameters["lastname"] = "Contact";
formParameters["fullname"] = "Sample Contact";
formParameters["emailaddress1"] = "contact@adventure-works.com";
formParameters["jobtitle"] = "Sr. Marketing Manager";
formParameters["donotemail"] = "1";
formParameters["description"] = "Default values for this record were set programmatically.";
// Set lookup column
formParameters["preferredsystemuserid"] = "3493e403-fc0c-eb11-a813-002248e258e0"; // ID of the user.
formParameters["preferredsystemuseridname"] = "Admin user"; // Name of the user.
formParameters["preferredsystemuseridtype"] = "systemuser"; // Table name.
// End of set lookup column
// Open the form.
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
Related topics
Feedback
Submit and view feedback for