The CreatorCon Call for Content is officially open! Get started here.

UI Policy is not able to filter dependent field

saptarshiamc
Tera Contributor

In the Change Request form, the 'Category' field depends on the 'u_area' field. When a user selects 'UTA' in the 'u_area' field, four options ('Asset Replacement', 'Asset Transfer', 'Asset Name Change', and 'Asset Disposal') are available in the 'Category' field.

However, a specific requirement entails that if the user selects 'UTA' in the 'u_area' field and possesses the role of 'Disposal Manager', only the 'Asset Disposal' option should be visible in the 'Category' field along with the others, but not visible otherwise.

 

This is working for other fields that are not dependent, however not working on dependent fields. Need your suggestion

1 ACCEPTED SOLUTION

In both cases the system is retrieving the dependent category choices when the area changes, likely after your script has completed.  Try setting an interval or timeout prior to the clear or remove.  Since it's reloading the choices with every change, you should just need to remove the one choice if they don't have the role - no need to clear all and re-add the other choices:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var uArea = g_form.getValue('u_area');
    if (uArea ==='8ba3a6aa47c1b9185f03bd01336d43bc') {
        var isAdmin = g_user.hasRole('Disposal Manager');
        if (!isAdmin) {
            alert ('not Admin');    
            setInterval(function() {
                g_form.removeOption('category', 'Asset Disposal');
            }, 2000);
        }
    }
}

wrapping the removeOption in a setInterval function may also work in a UI Policy script, depending on the timing of a UI Policy execution vs Client Script and the dependent field retrieval.

View solution in original post

6 REPLIES 6

saptarshiamc
Tera Contributor

@Brad Bowman  Thank you for the solution. This solution is working fine for me.

You are welcome.