Hello Folks,
Is it not a good learning experience,where you do relative comparison? I wrote a JavaScript to understand how formContext.ui.formSelector and its sub property work completely.
Please, take a look on high level overview of formContext.ui.formSelector which is tabulated below.
Scenario: I took the scenario where will set entity form based on option set value.This scenario covers ui.formselector entirely, likewise as:
- formContext.ui.formSelector.items.get();
- formContext.ui.formSelector.getCurrentItem.getId();
- formContext.ui.formSelector.getCurrentItem.getLabel();
- formContext.ui.formSelector.getCurrentItem.navigate();
Implementation: Find the code snippet below:
var formContext;
function setForm(executionContext)
{
formContext = executionContext.getFormContext();
if(formContext.ui.getFormType()==1)
{
return;
}
if (formContext.ui.getFormType()==2)
{
var caseType = formContext.getAttribute(logicalname).getValue();
switch(caseType)
{
case 1:
changeForm(“Claim”);
break;
case 2:
changeForm(“Trial Order”);
break;
default:
changeForm(“Case for Interactive experience”);
}
}
}
function changeForm(formName)
{
var currentForm = formContext.ui.formSelector.getCurrentItem();
var availableForms = formContext.ui.formSelector.items.get();
if (currentForm.getLabel().toLowerCase() != formName.toLowerCase())
{
for (var i in availableForms)
{
var form = availableForms[i];
// to find a form based on the name
if (form.getLabel().toLowerCase() == formName.toLowerCase())
{
form.navigate();
return true;
}
}
}
}
Call this function on page load event and make sure that this code is present on all other forms.
Testing: I am creating case record from default case form by putting up case type as Trial order.Once record is saved.It will navigate screen to trial order case form and have similar behavior for claims case form too.
Hope it is informative! 🙂 Keep dynamics-power with you.