Select which form to display based on OptionSet Value

Forum Post: Change the Filter On option on Opportunity Associated View for Account form

Hi all, 

I am struggling with this (hopefully very simple) problem. 

I have created a global option set on the contact entity called Type Of Contact.

The options are




I have 2 forms called

Student Form

Staff/Teacher Form.

I would like to use the script below to choose the student form when Type of contact = student and Staff/Teacher form when Type of contact = Staff or teacher.

I have created an onload web resource but I cannot get the code quite right. I understand this will give me the double load when the record is loaded.

The default form is the Student Form.

I am very new to jscripting so any help would be great.

function displaycorrectForm() {

//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_typeofcontact”).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 = “is this the option set value or the form name”;


case 2:

lblForm = “is this the option set value or the form name”;



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


} //endif

} //endif

} //end for

} //endif

} //endif

} //end function

Source link

Leave a reply

Please enter your comment!
Please enter your name here