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)

Select which form to display based on OptionSet Value

(0) ShareShare
ReportReport
Posted on by 3,070

Hi all,

I am wondering if anyone can advise how to get CRM to select which entity Form to display based on the value in an OptionSet field?  I know this could be done in older versions, but not sure if it is still possible in CRM 2016 Online/Dynamics 365 Online?  

Thanks,

Ryan

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    You could use JavaScript to check the value in the onload event of your default form.  Then load the new form based on the value.  I did something similar a while back but can't find the code.  Here is a link to something I think might work for you.

    https://social.microsoft.com/Forums/en-US/5ba919f7-9f7c-4abf-ba88-224951bb7c11/crm-2011-select-form-layout-depending-on-an-field-value?forum=crmdevelopment

  • Ryan Maclean Profile Picture
    3,070 on at

    Hi Ilgy,

    I've got some javascript code, but I don't think it works with the updated turboforms on CRM 2016/D365, so I'm looking for a supported method of achieving this which works in the latest versions

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Hi,

    Did you tried Xrm.Page.ui.formSelector.items[0].navigate.

    using Xrm.Page.ui.formSelector.items you will get collection of available forms for entity and using navigate method you can open specified form.

    for more detail please check

    msdn.microsoft.com/.../gg309560.aspx

  • Verified answer
    Ryan Maclean Profile Picture
    3,070 on at

    Hi Mahadeo,

    I am admittedly a bit limited in my ability to write js, but the code I'm using is below:

    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("leadsourcecode").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 = "Lead Form 1";

     break;

     case 2:

     lblForm = "Lead Form 2";

     break;

     default:

     lblForm = "Default Lead";

    }

    // 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

    It works, although it loads the default form and then reloads to the correct form.  I'm not sure if there is any way to avoid this?

  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at

    As you want to redirect form based on option set value, there is no other way than this.

    To execute code which is on default form's on load, need to load default form and needs to check option set value to redirect appropriate form.

  • Verified answer
    Community Member Profile Picture
    on at

    You could make the default form very simple just option so that it will load and redirect faster and add code to route to specific form for entity creation ( type code = 1)

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