SBX - Search With Button

SBX - Forum Post Title

Select which form to display based on OptionSet Value

Microsoft Dynamics CRM Forum

Ryan Maclean asked a question on 17 Feb 2017 8:13 AM
My Badges

Question Status

Verified

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

Reply
ilgy responded on 17 Feb 2017 8:25 AM
My Badges
Suggested Answer

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

Reply
Ryan Maclean responded on 17 Feb 2017 8:50 AM
My Badges

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

Reply
Mahadeo Matre responded on 17 Feb 2017 9:10 AM
My Badges
Suggested Answer

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

Reply
Ryan Maclean responded on 17 Feb 2017 9:38 AM
My Badges
Verified Answer

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?

Reply
Mahadeo Matre responded on 17 Feb 2017 9:44 AM
My Badges
Verified Answer

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.

Reply
ilgy responded on 17 Feb 2017 9:47 AM
My Badges
Verified Answer

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)

Reply
Ryan Maclean responded on 17 Feb 2017 9:38 AM
My Badges
Verified Answer

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?

Reply
Mahadeo Matre responded on 17 Feb 2017 9:44 AM
My Badges
Verified Answer

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.

Reply
ilgy responded on 17 Feb 2017 9:47 AM
My Badges
Verified Answer

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)

Reply
ilgy responded on 17 Feb 2017 8:25 AM
My Badges
Suggested Answer

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

Reply
Mahadeo Matre responded on 17 Feb 2017 9:10 AM
My Badges
Suggested Answer

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

Reply

SBX - Two Col Forum

SBX - Migrated JS