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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Open Specific Form Based on Field Value

(0) ShareShare
ReportReport
Posted on by

I have reviewed other posts regarding this subject, but was wondering if there has been any change (or if there is any planned change) on the ability of setting up a form to open up based on field value.

Ex.

If an account is a child account, open a main form designed strictly for Child Accounts.

If an opportunity is classified as Product A, open Form A.

The idea is to have this incorporated when user is following business process flows, for it to automatically open up the correct Form for the corresponding Entity, rather than have the User have to do so manually. Also when opening certain records that the correct form opens instead of the last form the User was on from a given entity...

*This post is locked for comments

I have the same question (0)
  • mcw1882 Profile Picture
    on at

    Preferably without using any coding...

  • Verified answer
    Royal King Profile Picture
    27,686 on at

    I dont think there is a way to do this without any coding.You have to use either script or plugin

    here is the script that can change formtype based on value

    function showForm() {

    //if the form is update form

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

       // variable to store the name of the form

       var lblForm;

       // get the value picklist field

       var relType = Xrm.Page.getAttribute("customertypecode").getValue();

       // switch statement to assign the form to the picklist value

       //change the switch statement based on the forms numbers and picklist values

       switch (relType) {

           case 1:

               lblForm = "Information1";

               break;

           case 2:

               lblForm = "Information2";

               break;

           default:

               lblForm = "Information";

       }

       //check if the current form is form need to be displayed based on the value

       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) {

                   //navigate to the form

                   item.navigate();

               } //endif

           } //end for

       } //endif

    }//endif

    } //end function

    Plugin to change formtype based on field value

    gonzaloruizcrm.blogspot.com/.../avoiding-form-reload-when-switching-crm.html

  • mcw1882 Profile Picture
    on at

    And if I recall from a previous reply on a similar post, there is no way for this to work on a new record, only on update, correct?

  • Royal King Profile Picture
    27,686 on at

    you can do this on new record as well based on form state like if form state is new and there is no value in parent lookup field open form type that is specific to sub account otherwise open in it in other form type that is specific to parent account.

  • mcw1882 Profile Picture
    on at

    Having difficulty getting this to work. I have 3 custom forms under the Account entity.

    There is a custom option set field "new_accounttype" which has 3 items.

    Customer

    Location

    Container

    I created the library, with the following code:

    function showForm() {

    //if the form is update form

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

       // variable to store the name of the form

       var lblForm;

       // get the value picklist field

       var relType = Xrm.Page.getAttribute("new_accounttype").getValue();

       // switch statement to assign the form to the picklist value

       //change the switch statement based on the forms numbers and picklist values

       switch (relType) {

           case 1:

               lblForm = "Location";

               break;

           case 2:

               lblForm = "Container";

               break;

           default:

               lblForm = "Customer";

       }

       //check if the current form is form need to be displayed based on the value

       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) {

                   //navigate to the form

                   item.navigate();

               } //endif

           } //end for

       } //endif

    }//endif

    } //end function

    Currently it is always going to the default. Can you tell me what I'm doing wrong?

  • Community Member Profile Picture
    on at

    With CRM Online Update 1 (May) ther is a new redering engine for Forms.

    Have you seen this script working with the new rendering engine?

  • mcw1882 Profile Picture
    on at

    I was able to get it working,  but i also had to set the library up to fire OnSave.

    Will try and confirm next week.

  • Community Member Profile Picture
    on at

    Got it to working .... Thanks for providing help.

    The only minor thing is that the original form loads first before the script loads the right one. - Looks like a little refresh all the time when loading a record.

    function jpe_showForm() {

    //if the form is update form

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

    // variable to store the name of the form

    var lblForm;

    // get the value picklist field

    var relType = Xrm.Page.getAttribute("new_campaignmode").getValue();

    // switch statement to assign the form to the picklist value

    //change the switch statement based on the forms numbers and picklist values

    switch (relType) {

      case 1:

      lblForm = "Campaign Main";

      break;

      case 2:

      lblForm = "Campaign Individual";

      break;

      default:

      lblForm = "Campaign Main";

    }

    // Current form's label

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

    //check if the current form is form need to be displayed based on the value

       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

  • Denisse Luna Profile Picture
    on at

    Do you know how to do this only the first time? As in, in the OnLoad, show the correct form but if the user selects another form from the OOB picklist of Forms, allow this. Currently, if I try to change to another form, it realoads the code and opens the same form again

  • mcw1882 Profile Picture
    on at

    The only way I was able to get it to work in 2015 Online was to have it run OnSave. OnLoad it did the same thing you are experiencing now.

    Here is a link that may assist you.

    gonzaloruizcrm.blogspot.com/.../avoiding-form-reload-when-switching-crm.html

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans