Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

URL Field Readonly

bishalsharm
ServiceNow Employee

Hi,

Not able to make a particular URL type field read-only or editable based on role or group validation.

here is the script:

Business Rule (Display)

 

(function executeRule(current, previous /*null when async*/ ) {

    g_scratchpad.userRole = gs.hasRole('xxxx');
    g_scratchpad.userGroup = gs.getUser().isMemberOf('xxxx');

    gs.info("Role: " + g_scratchpad.userRole);
    gs.info("Group is: " + g_scratchpad.userGroup);

})(current, previous)

 

 Client Script (onload)

 

function onLoad() {
     var userR = g_scratchpad.userRole;
    var userG = g_scratchpad.userGroup;
    if (userR == 'true' || userG == 'true') {
        g_form.setReadOnly('xxxx', false);
		g_form.setMandatory('xxxx', true);
    } else {
        g_form.setReadOnly('xxxx', true);
    }

}

 

 

problem: Even though the logged in user has either role or group but the URL type field is not showing as editable.

10 REPLIES 10

I have logged the g_scratchpad values in the client script and can see that one of them is returning true but still no luck