gs.getUserID() need basic understanding.

naresh1019
Mega Expert

Hello Guys .....Can you please guide with the following requirement.

1) I have a form with with only two date fields.

2) I want to create ACL to update the entries depending on the users who creaetd it .

3) find_real_file.png

The following sript condition is not working.

4) please guide me ,

1 ACCEPTED SOLUTION

tvani
Tera Contributor

Hi Naresh,



You can use the below script as sys_created_by stores the user_name of the user.



if(current.sys_created_by.equals(gs.getUserName())


return true;


View solution in original post

21 REPLIES 21

FYI, gs.getUserID() returns the sys_id of the logged in user.


And the comparison will never be true as you're comparing the sys_id with the email id of the user.



You should be able to check it with - answer = (gs.getUserID() == current.opened_by);



OR, if opened by is not present then you can glide the user table -



var usr = new GlideRecord('sys_user');


usr.addQuery('user_name',current.sys_created_by);


usr.query();


if(usr.next())


{


answer = (usr.sys_id == gs.getUserID());


}


Hi Neetu ,



as you said



find_real_file.png


I already have a system created field sys_created_by . So i dont want to query the tbale


tvani
Tera Contributor

Hi Naresh,



You can use the below script as sys_created_by stores the user_name of the user.



if(current.sys_created_by.equals(gs.getUserName())


return true;


sys_created_by is returning UserID so can userID and UserName be same.


I have not tried it . let me try


tvani
Tera Contributor

User ID is the label name and the column name is user_name in the User table. Yes, please try and let me know, if it works.