Most of the customers wanted to have a different form based on a particular field value and due to this we need to have custom functionality that improves the efficiency of the product.
In this blog, we will learn how to Change the form based on field value.
To achieve this, we need to have a XRM toolbox setup in your computer and connected to your working CRM Environment.Use Case:
One of our Customer has requirement where the CRM Form should load based on Lookup value.
We have Two different Forms under Contact entity i.e., Contact and Contact 1.
When we create a new Contact from Contact Entity Prospect then Contact Form should load and on change of Preferred method contact field other form Should be visible.
formContext = executionContext.getFormContext();
var newForm;// Get Current Form Name
var formName = formContext.ui.formSelector.getCurrentItem().getLabel();
// Get Entity name of the lookup Field
var callTo = formContext.data.entity.attributes.get(“regardingobjectid”).getValue().entityType;
// Based on Entity name Form Name
newForm = “Prospect Phone Call”;
newForm = “Phone Call”;
if (formContext.ui.formSelector.getCurrentItem().getLabel() != newForm)
var items = Xrm.Page.ui.formSelector.items.get();
for (var i in items)
var item = items[i];
var itemId = item.getId();
var itemLabel = item.getLabel()
if (itemLabel == newForm)
//navigate to the form
- Call function on Load of Both forms
Open the entity form by navigating to Settings → Customizations → Customize the System → required entity → Forms → Main Form.
- Click Form Properties.
Refer below example.
- From the Form Properties window, click Add.
In the next Look Up Web Resource Record window, search for newly created webresource, select it and click Add.
You have now successfully added a new web resource and registered it on the form.
Control − Preferred Method of Communication
Event − OnChangeThen, click the Add button, as shown in the following screenshot.
- In the next window Select Library as new_contacts.js and Function as validatePreferredMethodOfCommunication.
- Click Save followed by Publish.