Hey, Many times one needs to show some value at a time in an option set and other at other time based on some condition on a CRM form:
Here i have an example in which we have 1 option set field "optionsetfieldSchemaname" with 8 option values and another option set field "ControllerfieldSchemaname" with 2 values.
Now the user wants to display first 4 values of "optionsetfieldSchemaname" field when 1st option is selected in controller option set "ControllerfieldSchemaname" and last 4 options to be displayed when 2nd option is selected in controller option set "ControllerfieldSchemaname".
Run this JS on change of controller option set "ControllerfieldSchemaname".
////////////////////////////////////////////////////////////////
function Hideoptions()
{
debugger;
//Option Set with 8 option values
var optionsetControl = Xrm.Page.ui.controls.get("optionsetfieldSchemaname");
var options = optionsetControl.getAttribute().getOptions();
//Controller Fields
var value = Xrm.Page.getAttribute("ControllerfieldSchemaname").getValue();
if (value == 1)
{
optionsetControl.clearOptions();
for (var i = 0; i < options.length - 1; i++)
{
if (i == 0 || i == 1 ||i==2||i==3)
{
optionsetControl.addOption(options[i]);
}
}
}
else if(value==2)
{
optionsetControl.clearOptions();
for (var i = 0; i < options.length - 1; i++)
{
if (i == 4|| i == 5|| i == 6|| i == 7)
{
optionsetControl.addOption(options[i]);
}
}
}
}
////////////////////////////////////////////////////////////////
So You may achieve similar functionality on the basis of different conditions.
Thanks,
No comments:
Post a Comment