Created
August 11, 2020 21:35
-
-
Save DynCon365/204d031d95090b469465d305828f1c8c to your computer and use it in GitHub Desktop.
Dynamics 365/CRM 9.0+ | Open a specific form based on a field value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------------------- | |
// openSpecificForm | |
//------------------------------------------------------------------------------------------- | |
function openSpecificForm(e){ | |
// Get the Form Context | |
var formContext = e.getFormContext(); | |
//if the form is update form | |
if (formContext.ui.getFormType()==2) { | |
// variable to store the name of the form | |
var lblForm; | |
// get the value picklist field | |
var relType = formContext.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 (formContext.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(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment