Record producer script to add user to watch_list

M_iA
Kilo Sage

Hello!

I have a record producer and I am trying to write a script for it that checks whether the current user has a specific role and if they do, to add th user to the watch list when the form is submitted.

Please could someone help me out with this?

Thanks

1 ACCEPTED SOLUTION

AnubhavRitolia
Mega Sage
Mega Sage

Hi,

 

Assuming you are talking about Logged in User. Please find code below:

 

if(gs.hasRole('<roleName>')) {
current.watchlist = gs.getUserID();
current.update();
}

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

5 REPLIES 5

AnubhavRitolia
Mega Sage
Mega Sage

Hello,

 

By Current User, do you mean Logged in User or there is a variable which will store user record?

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Its the current logged on user.

Thanks

AnubhavRitolia
Mega Sage
Mega Sage

Hi,

 

Assuming you are talking about Logged in User. Please find code below:

 

if(gs.hasRole('<roleName>')) {
current.watchlist = gs.getUserID();
current.update();
}

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

That will work but it will clear values (if any) in the watchlist and run for admin when they don’t have the specific role.