ACL script for matching user ID with field on record

patricklatella
Mega Sage

hey gang,

I'm debugging some ACLs, one in particular has a condition I'm trying to set in script so that the logged in user can read fields on a record only if they are the current entry in one of the fields.

which is of these would be correct?   does my script have to have a line for "answer = true"?

var u = gs.getUserID(); //sets u to ID of current user

answer = current.u_customer_contact == u || current.opened_by == u || current.isNewRecord() || !current.getUniqueValue();

OR...

var u = gs.getUserID(); //sets u to ID of current user

if (current.u_customer_contact == u || current.opened_by == u || current.isNewRecord() || !current.getUniqueValue()) {

answer = true;

}

find_real_file.png

1 ACCEPTED SOLUTION

Justin Abbott
Giga Guru

You don't need to explicitly state answer = true.



As long as answer evaluates to either true or false.



Stylistically, I'd throw some parenthesis in there, but that's just my preference.



var u = gs.getUserID(); //sets u to ID of current user


answer = (current.u_customer_contact == u) || (current.opened_by == u) || (current.isNewRecord()) || (!current.getUniqueValue());


View solution in original post

6 REPLIES 6

patricklatella
Mega Sage

actually figured it out...thanks Justin!


Adam43
Tera Contributor

think i'm trying to figure out a similar issue.  ours is to compare the current user's Company value against the record(on sys_user) and restrict write access to one particular field.  not quite working yet.

 

var companyID = gs.getUser().getCompanyID();
answer == (user.isMemberOf("ITSM Service Desk Notes")) && (current.u_company == companyID);