- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2019 08:51 PM
Trying to refine a Business Rule that works on BEFORE insert or update.
On a catalog item I have the following:
- Hiring Manager - single user reference variable
- CCs - UI Macro with label variable that mimics WatchList - returns user sys_id
- Interested Parties - single text variable with comma separated list of emails.
- WatchList with previous additions from script or manually added by agents
What I need is a way to add the sys_ids/emails from items 1 to 3 to the existing watchlist but then do a check to ensure there are no duplicates before adding it into the record. Want to be able to dynamically deal with adding any new emails/users to these lists after original submissions.
Solution needs to be ES5 compliant - not ES6
Every example I have found and implemented just is not working and keeps producing errors.
// Get current watchlist
var currentWL = current.watch_list.toString().split(",");
gs.log("starting watchlist: " + current.watch_list.toString())
// external email addrsses
var intParties = current.variable_pool.jobOpen_unit_intPartyEmail.split(",");
// list of users in watchlist like macro variable
var cc = current.variable_pool.jobOpen_unit_cc.toString().split(",");
// single person user
var hMgr = current.variables.jobOpen_unit_hireMgr.email; // single person user
var newEmails = intParties +"," + cc + "," + hMgr;
gs.log ("Combined email list is " + newEmails);
var updatedWL = currentWL + "," + newEmails;
gs.log ("Updated Watch List is " + updatedWL);
current.watch_list = updatedWL;
+++++++++++++++++++++++++++++++ CODE WORKS UP TO HERE ++++++++++++++++++++++++
// Remove duplicates
updatedWL = deduper = {};
updatedWL.forEach(function(item) {
deduper[item] = null;
var uniqueArray = Object.keys(deduper);
});
gs.log ("Unique array is " + uniqueArray);
//current.watch_list = uniqueArray;
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2019 10:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2019 10:41 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2019 12:42 AM
Hi ,
You can try the below:
var currentWL = "test1@gmail.com,test2@gmail.com,test3@gmail.com";
var newEmails = "test1@gmail.com,test2@gmail.com,test7@gmail.com";
var updatedWL = currentWL + "," + newEmails;
gs.log ("Updated Watch List is " + updatedWL);
var emailArray = updatedWL.split(',');
var arrayUtil = new ArrayUtil();
//with duplicates
gs.log(emailArray);
var finalArray = arrayUtil.unique(emailArray);
//without duplicates
gs.log(finalArray.toString());
//current.watch_list = finalArray.toString();
-Satheesh