Dynamics 365 CRM Form Switching: A Deep Dive into formSelector and navigate()
In the dynamic landscape of Dynamics 365 Customer Relationship Management (CRM), the ability to present different forms to various user groups based on specific conditions is a common and powerful customization requirement. Fortunately, the formSelector
object, coupled with the navigate()
function, provides an elegant solution to this challenge, allowing for seamless form switching based on user roles and other criteria.
FormSelector Object
At the heart of this functionality lies the formSelector
object, a JavaScript object that acts as a gateway to managing forms within Dynamics 365 CRM. The formSelector
object grants access to a collection of items, representing all the forms accessible to the current user. It's important to note that these forms are filtered based on the user's security roles, ensuring a secure and controlled form-switching experience.
Exploring the items Collection
Within the formSelector
object, the items
collection stands out as a crucial repository of information. Each item in this collection corresponds to a specific form available in the CRM instance. This collection becomes invaluable when checking for user access rights before initiating a form switch.
eg: var formItem = formContext.ui.formSelector.items.get(arg);
arg
represents the identifier or condition used to select a specific form item from the collection.Navigate() Function
The navigate()
function is the key to dynamically switching between forms. Taking a form item as a parameter, this function directs the CRM interface to display the selected form. This proves especially useful when conditions are met, and you want to dynamically present the most relevant form to the user.
eg: formContext.ui.formSelector.items.get(arg).navigate();
Obtain Form Id
Navigate to solution and select the entity and select the form in edit mode. From the URL the id of the form can be obtained.
Check the below code for full implementation.
function formSwitch(executionContext) { // Get the form context var formContext = executionContext.getFormContext(); // Get the value of the field that triggers the change var individualType = formContext.getAttribute("merpin_individualtype").getValue(); // Define the form names to switch between var referralForm = "Your Form Id"; var serviceProvider = "Your Form Id"; // Check the field value and switch forms accordingly if (individualType !== null){ //Referral/Accused if (individualType == 1) { formContext.ui.formSelector.items.get(referralForm).navigate(); } //Service Provider else if (individualType == 2) { formContext.ui.formSelector.items.get(serviceProvider).navigate(); } } }
Comments
Post a Comment