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.

URL Field Readonly

bishalsharm
ServiceNow Employee
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

bishalsharm
ServiceNow Employee
ServiceNow Employee

I accidently accpeted your solution, though i update the client script but no luck

bishalsharm
ServiceNow Employee
ServiceNow Employee

this update didn't work for me
also, the client script is for a custom view 
i have mentioned the view name as well by unchecking the global checkbox and entered the view name

Ankur Bawiskar
Tera Patron
Tera Patron

@bishalsharm 

did you add alert and debug?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

yes i added the alert and alerts are positively showing that the user is the member of the group but still the url type field is not editable

t_sadahisa
Giga Guru

@bishalsharm 

 

It may be that the client script is running faster than the timing at which values are assigned to g_scratchpad.

 

Why not check the value of g_scratchpad that can be obtained by the client script?

 

Otherwise, it may be a good idea to use GlideAjax for processing.
Simply create a client callable Script include and respond whether it matches the conditions.