- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 01:48 AM
I have created a Before Update BR , in this i script i have achieved adding users to the watchlist when the watchlist is empty and when the watchlist is having some existing values ( , separated).
Note: I want to avoid duplicate user's entry into the watchlist. How can i achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 02:36 AM - edited 08-02-2024 02:41 AM
// Retrieve the list of watchers from the property
var watchers = gs.getProperty('test.user.watch');
// If the current watch_list is empty, set it to the property value
if (current.watch_list.nil()) {
current.watch_list = watchers;
} else {
// Convert the current watch_list value to an array and split it by commas
var currentWatchers = current.watch_list.toString().split(',');
// Convert the property value to an array by splitting it by commas
var newWatchers = watchers.toString().split(',');
// Add new watchers to the list if they are not already present
newWatchers.forEach(function(watcher) {
if (currentWatchers.indexOf(watcher) === -1) {
currentWatchers.push(watcher);
}
});
// Set the updated watch_list value with no duplicates
current.watch_list = currentWatchers.join(',');
}
})(current, previous);
Comments Translation
Retrieve the list of watchers from the property
- Retrieves the watcher list from the system property.
If the current watch_list is empty, set it to the property value
- Checks if the current watch_list is empty and sets it to the value from the property if so.
Convert the current watch_list value to an array and split it by commas
- Splits the existing watch_list value into an array by commas for processing.
Convert the property value to an array by splitting it by commas
- Splits the property value into an array by commas.
Add new watchers to the list if they are not already present
- Adds each new watcher to the list if it is not already included.
Set the updated watch_list value with no duplicates
- Joins the array back into a comma-separated string and sets it as the new watch_list, ensuring no duplicates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 02:36 AM - edited 08-02-2024 02:41 AM
// Retrieve the list of watchers from the property
var watchers = gs.getProperty('test.user.watch');
// If the current watch_list is empty, set it to the property value
if (current.watch_list.nil()) {
current.watch_list = watchers;
} else {
// Convert the current watch_list value to an array and split it by commas
var currentWatchers = current.watch_list.toString().split(',');
// Convert the property value to an array by splitting it by commas
var newWatchers = watchers.toString().split(',');
// Add new watchers to the list if they are not already present
newWatchers.forEach(function(watcher) {
if (currentWatchers.indexOf(watcher) === -1) {
currentWatchers.push(watcher);
}
});
// Set the updated watch_list value with no duplicates
current.watch_list = currentWatchers.join(',');
}
})(current, previous);
Comments Translation
Retrieve the list of watchers from the property
- Retrieves the watcher list from the system property.
If the current watch_list is empty, set it to the property value
- Checks if the current watch_list is empty and sets it to the value from the property if so.
Convert the current watch_list value to an array and split it by commas
- Splits the existing watch_list value into an array by commas for processing.
Convert the property value to an array by splitting it by commas
- Splits the property value into an array by commas.
Add new watchers to the list if they are not already present
- Adds each new watcher to the list if it is not already included.
Set the updated watch_list value with no duplicates
- Joins the array back into a comma-separated string and sets it as the new watch_list, ensuring no duplicates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 02:53 AM
Thanks for the quick response, let me test this form my end and get back to you.