Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Make Catalog variables Readonly for Specific Groups

Vamshi_ch123
Tera Contributor

Hi, I would like to set catalog variables as read-only for two specific groups. I've created a new role and assigned this role to those groups based on information from a community blog and implemented the following onLoad client script. However, when I impersonate and check, it still doesn't seem to be working.

 

function onLoad() {
    // Ensure that g_form is defined and available
    if (typeof g_form !== 'undefined' && g_form) {
        var SaaSUser = g_user.hasRoleExactly('PAM_Access_Groups');
        if (SaaSUser) {
            g_form.setReadOnly('lob', true);
            g_form.setReadOnly('customer', true);
            g_form.setReadOnly('group_name', true);
            g_form.setReadOnly('group_to_be_added', true);
            g_form.setReadOnly('first_user_name', true);
        }
    }
}

 

Thank you

4 REPLIES 4

Hristo Ivanov
Kilo Sage
Kilo Sage

Hi @Vamshi_ch123 ,

 

Have you set the type of Client Script to all? 

 

Please mark this response as correct and helpful if it helps you

Hi @Hristo Ivanov , 

 

Yes, It was set to all

Vamshi_ch123_0-1700386540869.png

 

Vamshi_ch123_1-1700386695529.png

 

Thank you

 

Uncheck 'Isolate script' and try below once.

 

function onLoad() {
    // Ensure that g_form is defined and available
    if (typeof g_form !== 'undefined' && g_form) {
        var SaaSUser = g_user.hasRoleExactly('PAM_Access_Groups');
        if (SaaSUser.toString()) == 'true') {
            g_form.setReadOnly('lob', true);
            g_form.setReadOnly('customer', true);
            g_form.setReadOnly('group_name', true);
            g_form.setReadOnly('group_to_be_added', true);
            g_form.setReadOnly('first_user_name', true);
        }
    }
}
Please hit like and mark my response as correct if that helps
Regards,
Musab

Musab Rasheed
Tera Sage

Hello,

Try below.

https://www.servicenow.com/community/developer-forum/set-variable-to-read-only-based-on-role/m-p/162...

Please hit like and mark my response as correct if that helps
Regards,
Musab