
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2022 06:40 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2022 06:53 AM
Hi,
Assuming you are talking about Logged in User. Please find code below:
if(gs.hasRole('<roleName>')) {
current.watchlist = gs.getUserID();
current.update();
}
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2022 06:48 AM
Hello,
By Current User, do you mean Logged in User or there is a variable which will store user record?
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2022 06:51 AM
Its the current logged on user.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2022 06:53 AM
Hi,
Assuming you are talking about Logged in User. Please find code below:
if(gs.hasRole('<roleName>')) {
current.watchlist = gs.getUserID();
current.update();
}
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2022 07:57 AM
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.