- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 12:32 AM
hi there!
I have a Problem watchlist already has some user, say original1@gmail.com and original2@gmail.com.
I added the below BIZ Rule Script, it seems like it will replace the original1@gmail.com and original2@gmail.com and add in the below testing1@gmail.com.
I'm trying to prevent the replace, but to add in more email addresses. How can i do that in UI?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 02:07 AM
Hi @Max Lin
So here we can have a if validation and check whether gmail is already present or not.
If not present then add those gmails into watchlist.
Here is the updated logic:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if (current.u_list_user.indexOf("testing1@gmail.com") < 0)
current.u_list_user += "," + "testing1@gmail.com";
if (current.u_list_user.indexOf("testing3@gmail.com") < 0)
current.u_list_user += "," + "testing3@gmail.com";
if (current.u_list_user.indexOf("testing2@gmail.com") < 0)
current.u_list_user += "," + "testing2@gmail.com";
//current.watch_list+=","+"testing1@gmail.com"+","+"testing2@gmail.com"+","+"testing3@gmail.com";
})(current, previous);
Hope it helps
(=tested)
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 12:55 AM - edited 10-17-2022 01:09 AM
Hi @Max Lin
In advanced script section try below logic:
current.watch_list+=","+"testing1@gmail.com"+","+"testing2@gmail.com"+","+"testing3@gmail.com";
Hope it helps
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 01:57 AM
Hi Murthy! Thanks for your reply!
I tested, seems like everytime it's adding the same email address everytime the business rule criteria matches.
Is there anyway we can do a check before applying the adding of email?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 02:07 AM
Hi @Max Lin
So here we can have a if validation and check whether gmail is already present or not.
If not present then add those gmails into watchlist.
Here is the updated logic:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if (current.u_list_user.indexOf("testing1@gmail.com") < 0)
current.u_list_user += "," + "testing1@gmail.com";
if (current.u_list_user.indexOf("testing3@gmail.com") < 0)
current.u_list_user += "," + "testing3@gmail.com";
if (current.u_list_user.indexOf("testing2@gmail.com") < 0)
current.u_list_user += "," + "testing2@gmail.com";
//current.watch_list+=","+"testing1@gmail.com"+","+"testing2@gmail.com"+","+"testing3@gmail.com";
})(current, previous);
Hope it helps
(=tested)
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 02:12 AM - edited 10-18-2022 02:13 AM
Hi @Max Lin ,
You can put a check before adding a new email address to the watchlist by using below code:
var watcList = current.watch_list.toString();
var email = 'the email you want to add';
if(watcList.indexOf(email) ==-1){
current.watch_list+=","+email;
}
Please mark my answer as correct and helpful if it resolved your query.
Mohit Kaushik
ServiceNow MVP (2023-2025)