web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Opening Specific Form OnChange

(0) ShareShare
ReportReport
Posted on by 274

Working on Account Entity. I have created 4 other forms based on account. The main form has a field called "Account Type" which is an option set contains a dropdown value 4 forms.  When Account Type = 1, it will display the form within the main form. When Account Type =2, and so forth I would like to open the appropriate form OnChange

function new_showAccountForm() {

if (Xrm.Page.ui.getFormType()==2) {

var lblForm;

var accountType = Xrm.Page.getAttribute("new_account").getValue();

switch (relType) {
  case 1:
  lblForm = " Main";
  break;
  case 2:
  lblForm =  "Individual";
  break;
 case 3:
  lblForm =  "Individual3";
  break;
 case 4:
  lblForm =  "Individual4";
  break;
  default:
  lblForm = "Main";
}
// Current form's label
var formLabel = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

   if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
  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 == lblForm) {
 //Check the current form is the same form to be redirected.
 if(itemLabel != formLabel) {            
  //navigate to the form
  item.navigate();
 } //endif
  } //endif
  } //end for
   } //endif
} //endif
} //end function

*This post is locked for comments

I have the same question (0)
  • waghmare pallavi  Profile Picture
    on at
    RE: Opening Specific Form OnChange

    hi MituCrming you can try following code see if it works.

    // JScript source code

    function LoadSpecificForm() {

       var items = Xrm.Page.ui.formSelector.items.get();

       var CurrentFormtype = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

       var optionsetValue = Xrm.Page.getAttribute('new_loadformonchange').getValue();

       var currentFormId = Xrm.Page.ui.formSelector.getCurrentItem().getId();

       if (optionsetValue == 10) {

           Xrm.Page.ui.formSelector.items.get(0).navigate();

       }

       if (optionsetValue == 20) {

           Xrm.Page.ui.formSelector.items.get(1).navigate();

       }

    }

    i have used above code on my Department entity where i switch from one from to another form on onchange of Optionset value.Check if it works for you.

  • Suggested answer
    Zohaib Uddin Khan Profile Picture
    2,822 on at
    RE: Opening Specific Form OnChange

    Hi,

    Kindly check the openEntityForm of the Xrm.Utility object.

    Thanks.

  • MituCRMing Profile Picture
    274 on at
    RE: Opening Specific Form OnChange

    Hi pallavi waghmare,

    I tried your code, got an error on the getValue(). ( Unable to get property 'getValue' of undefined or null reference

      at LoadSpecificForm)

    new_loadformonchange, this is the optionset field right? also on this line of code where does the 0 coming from? Thanks!

      Xrm.Page.ui.formSelector.items.get(0).navigate();

  • Verified answer
    Zohaib Uddin Khan Profile Picture
    2,822 on at
    RE: Opening Specific Form OnChange

    Hi,

    Kindly check the openEntityForm of the Xrm.Utility object.

    Thank

  • Suggested answer
    Neil Parkhurst Profile Picture
    10,727 User Group Leader on at
    RE: Opening Specific Form OnChange

    The code below should change the form ....

    var formType = Xrm.Page.ui.getFormType();

    var currentForm = Xrm.Page.ui.formSelector.getCurrentItem().getId();

    var newForm = "<<Insert Name of Form to Load>>";

    var forms = Xrm.Page.ui.formSelector.items.get();

    var i = 0;

    for(i=0; i<forms.length; i++) {

               if (forms[i].getLabel().toLowerCase() == newForm.toLowerCase()) {

                   if (currentForm != forms[i].getId()) {

                       forms[i].navigate();

                   }

    }

    }

    It is very similar in principle to your code, as using "navigate".

  • MituCRMing Profile Picture
    274 on at
    RE: Opening Specific Form OnChange

    Thank you Neil. So I will list all of the forms then

    Var newForm  ="form1";

    Var newForm  = "form2";

    Etc since my option set field contains 4 drop downs which are forms that I will be navigating to onChange. I would also like to check the form onLoad ando onChange  force to Save.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans