Customizing Dynamics 365: Opening Specific Forms with Custom Buttons
Introduction Customizing user experience in Dynamics 365 can significantly improve efficiency and user satisfaction. One way to achieve this is by adding custom buttons to open specific main and Quick Create forms. This article introduces how to implement such customizations using JavaScript.
Opening a Specific Main Form
To open a specified main form, you can use the openForm
method. This method allows you to specify the form's GUID to ensure that the correct form is opened. Here's an example:
javascriptfunction openSpecificMainForm() {var entityFormOptions = {entityName: "account",formId: "your-form-id-here"};Xrm.Navigation.openForm(entityFormOptions).then(function (success) { console.log("Form opened successfully."); },function (error) { console.log("Error opening form:", error); });}
Replace "account"
with the entity logical name and "your-form-id-here"
with the form's GUID.
Pre-Populating Fields in Main Forms
You can also pre-populate fields when opening a main form. This is achieved by passing parameters with the openForm
method. Here's an example:
javascript
This script opens a specific main form for a contact entity and pre-populates the 'firstname' and 'lastname' fields.
Opening a Quick Create Form
For Quick Create forms, the openQuickCreate
method opens the default Quick Create form for the specified entity. Unlike main forms, you cannot specify which Quick Create form to open. Sample code:
javascriptfunction openQuickCreateForm() {Xrm.Utility.openQuickCreate("account").then(function (result) { console.log("Quick Create form opened successfully."); },function (error) { console.log("Error:", error.message); });}
Pre-Populating Fields in Quick Create Forms In addition to opening default Quick Create form, you can also pre-populate fields when opening a Quick Create form. Here are two scenarios:
Pre-Populating Based on Current Record:
javascriptvar parameters = { name: "Child account of " + Xrm.Page.getAttribute("name").getValue() };Xrm.Utility.openQuickCreate("account", null, parameters).then(// Callback functions);This opens a Quick Create form for an account, setting the 'name' field based on the current record's name.
Pre-Populating with Static Values:
javascriptfunction openQuickCreateWithParameters() {var entityName = "contact"; // Replace with your entity logical namevar parameters = {};parameters["firstname"] = "John"; // Pre-populating the 'firstname' fieldparameters["lastname"] = "Doe"; // Pre-populating the 'lastname' fieldparameters["your_optionset_fieldname"] = value; // Replace with the field name and the option set value (integer)parameters["your_lookup_fieldname"] = [{id: "record_guid", // GUID of the lookup recordentityType: "entity_logical_name", // Logical name of the entityname: "record_display_name" // Display name of the record}];Xrm.Utility.openQuickCreate(entityName, null, parameters).then(function (result) {console.log("Quick Create form opened successfully.");},function (error) {console.log("Error:", error.message);});}This opens a Quick Create form for a contact and pre-populates the 'firstname' and 'lastname' fields.
Conclusion Integrating these custom buttons into your Dynamics 365 environment can streamline workflows and enhance user interactions. Remember to test these
No comments:
Post a Comment