Make a field readonly in a business rule

lindac
Kilo Explorer

Is there a way to make a field readonly based on roles in a business rule. I cannot locate anyting on this site or the SN wiki site.

Thank you,

Linda

8 REPLIES 8

CapaJC
ServiceNow Employee
ServiceNow Employee

Probably, but first why a Business Rule? Could you instead use ACLs to do the same thing? Or a Client Script? I think any logic you could put in a Business Rule would also work in an ACL's conditions or script.

To use a Business Rule, you'd need to set a scratchpad variable in a "display" Business Rule, then use that variable in an onLoad Client Script to make the field read-only. When you could just do the role check in a client script by itself with a g_user.hasRole("my_role") check.


lindac
Kilo Explorer

Thank you for your quick reply. We need to use a Business Rule because we are not using ACLs and we currently have a onload Client script but it does not work in our Self-service form. I contacted Service Now concerning this and they said we need to have an onSubmit rule which does not serve our purpose.

As for your suggestion of using a scratchpad variable, this is new to me but based on your statement I will still need an onload client script which brings me back to my original issue.

Linda


CapaJC
ServiceNow Employee
ServiceNow Employee

Odd that your existing script wouldn't work on the ESS view. Would you mind posting it here (you could sanitize sensitive variable/field names if necessary)? Perhaps it is trying to use something that isn't on the ESS view of the form, and it's throwing a JavaScript error preventing the script from working.

Or, perhaps you have a completely unrelated client script that is throwing an error on form load of the ESS view, which will then prevent all other client scripts from working. That's a bit tougher to troubleshoot, but it's definitely a possibility.


lindac
Kilo Explorer

Hi, this is the client script we are using. I works fine in the default view.

function onLoad() {

// Changed referenced from priority to severity as needed
// Prevent Severity Downgrades of S1 or S2 Incidents

var IncAdminRole = g_user.hasRole('admin');
var IncCrisisRole = g_user.hasRole('crisis_editors');
var IncEditRole = g_user.hasRole('incident_editors');
var IncClsEditRole = g_user.hasRole('inc_close_editors');
var IncState = g_form.getValue('incident_state');
var lastUpdate = g_form.getValue('sys_updated_on');
var incSeverity = g_form.getValue('severity');

if (lastUpdate == ''){

g_form.setReadonly('severity',false);

}
else {

if (incSeverity > 2){

g_form.setReadonly('severity',false);

}
else {

if (incSeverity < 3 && (!IncAdminRole && !IncCrisisRole)){

g_form.setReadonly('severity',true);

}
else {

if ((IncAdminRole) || (IncCrisisRole)){

g_form.setReadonly('severity',false);

}
else {

if (IncEditRole && IncState == '6'){

g_form.setReadonly('severity',false);

}
else {

if (IncClsEditRole && IncState == '7'){

g_form.setReadonly('severity',false);

}
else {

g_form.setReadonly('severity',false);

}
}
}
}
}