Javascript – Form Navigate

As you can have multiple forms in Microsoft Dynamics CRM you may wish to navigate to a particular form from JavaScript.

The function below can be used to change the currently selected form.

ChangeForm("Test Form");
function ChangeForm(formName) {
  var currentForm = Xrm.Page.ui.formSelector.getCurrentItem();
  var availableForms = Xrm.Page.ui.formSelector.items.get();
  if (currentForm.getLabel().toLowerCase() != formName.toLowerCase()) {
    for (var i in availableForms) {
      var form = availableForms[i];
      // try to find a form based on the name
      if (form.getLabel().toLowerCase() == formName.toLowerCase()) {
        return true;

4 thoughts on “Javascript – Form Navigate

  1. hi Neil
    i have a related question , i you could answer it please.
    I have a custom activity entity that has several forms.
    when the users add a new activity the “regardingobjectid” attribute is set correctly, but if the user switches from the current form to a different form, the the “regardingobjectid” attribute is lost when the form reloads.
    the same bug happens on vanila activities (appointment).
    Is there a solution or a work around?
    thanks in advance.

    Liked by 1 person

    • Hi Doron

      Hard to be sure as I’d need to look deeply into your config!

      I am going to guess that the regardingobjectid field has been populated but the record not saved.

      Try saving before you change the form. If you find this works (manually) you may find the config isn’t simple. It will be possible but you will need to only change the form after the save has finished! (Running a save action can start the save but doesn’t tell us when complete! You can try adding something to the saved event but I’ve had mixed success with that!)

      Good luck



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s