should ACL script return true explicitly to grant access?

prasanna11
Mega Guru

should ACL script return true explicitly to grant access?

will this below ACL return true if any of the condition satisify ?

current.isNewRecord() || current.request.opened_by == gs.getUserID() || current.request.requested_for == gs.getUserID() || gs.hasRole('itil')

Or should this be wrapped inside a function as below?

checkAccess();

function checkAccess() {

if (current.isNewRecord() || current.request.opened_by == gs.getUserID() || current.request.requested_for == gs.getUserID() || gs.hasRole('itil')){

return true;

}

else{

return false;

}

}

1 ACCEPTED SOLUTION

harshvardhan_11
Giga Expert

Both will work in same manner.



As per the wiki


The script must generate a true or false response in one of two ways:


  • return an answer variable set to a value of true or false
  • evaluate to true or false.


So since both of the values return to true. It will work in both conditions


View solution in original post

5 REPLIES 5

Because of the usage of Global variables like current - the below link is for best practice for business rule but it applicable for all server side script -



"The recommended method for preventing such unexpected behavior is to always wrap your code in a function. This protects your variables from conflicting with system variables or global variables in other business rules that are not wrapped in a function."


Scripting in Business Rules - ServiceNow Wiki


Section 2



Not only server side script, its always advisable to wrap the variables in function even for client side script -


Client Script Best Practices - ServiceNow Wiki


Section 8



Mark if it is helpful