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

Community Alums
Not applicable

Hi Naresh,



The condition will never return true as:


gs.getUserID will return in form of sys_id . Ex.33fe5245c331210038bf506adfba8fcc


current.sys_created_by will return string. Ex. Naresh Chandurkar.



You should be using following condition if you want to check the validity of current user.


gs.getUserName() = current.sys_created_by;



Let me know if you still have issues.



Cheers,


Hardit Singh


Nope Not working.



My Question to you .



1) what does sys_created_by return what --> userID or user Name.


2) UserName returns what --> UserID /User NAme



My Observations


sys_careated_by-->returning userID


uer_name returns-->name


tvani
Tera Contributor

Hi Naresh,



User ID is the label name of the field, and it is referred as user_name in the scripts as it is the DB name. I hope the below information clears your doubt.


Please let me know, if it helps.


find_real_file.png


find_real_file.png


find_real_file.png


Hi Naresh,



The field User ID is having the label as User ID and column name as user_name


Which means both are one and the same


You can see by configure dictionary


find_real_file.png



Where as the function gs.getUserID() will return the sys_id of the currently logged in user


gs.getUserName() funcation will return the user_name which is the User ID field of the sys_user table



Check this link



getUserID()Returns the sys_id of the current user.
getUserName()

Returns the username of the current user (for example, jsmith).






http://wiki.servicenow.com/index.php?title=GlideSystem#gsc.tab=0


naresh1019
Mega Expert

find_real_file.png


find_real_file.png


Still the itil user is ablt to update the admin records