How to filter Option Set Field options based on form

 How to filter Option Set Field options based on form


In some scenarios, we may need to filter the option set types of fields' options based on some conditions.

Below is an example to filter the option set options based on the form(name).

1. Create JS below.

function filterStatusValues(executionContext)
{
    var formContext = executionContext.getFormContext();        
    var formName = null;
    var currentForm = formContext.ui.formSelector.getCurrentItem();
    if (currentForm != null)
    {
        formName = currentForm.getLabel();
    }    

    var applicationStatus = formContext.getControl("hs_applicationstatus");
    if (applicationStatus != null)
    {
        switch(formName)
        {
            case "Student Aid Application main form":
                applicationStatus.removeOption(123150002);
                break;
           
            case "Information":
                applicationStatus.removeOption(123150003);
                break;
        }
    }
}


2. Add this JS to all the forms you want it to be working on.


3. Switch the form, you will see the result.


Below is the details.



No comments:

Post a Comment