Switch Form in MS CRM with JavaScript

Client Side Programming Jan 25, 2017

The Microsoft XRM JavaScript Framework provides the possbility to switch/navigate to a specific form of an entity.

Often the use case is, that a type (e.g. OptionSet) has a dedicated form which should be shown when the type is set/changed.

In the first place you have to figure out the id of your target form – this id you’ll need later to execute the switch.

This example code iterates over all available form id’s until one of the available form id’s matches your target id. After the match the navigate function is called – which will be switch forms and presents theĀ target form to the actual user.

var targetFormId = [Your Target Form Id];
var availableForms = Xrm.Page.ui.formSelector.items.get();

for (var i in availableForms) {
     var form = availableForms[i];
       if (form.getId().toLowerCase() == targetFormId.toLowerCase()) {
                form.navigate();
       }
}

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.