- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 02:35 AM
Hi Team,
We have a requirement to remove the Group managers from Groups in group table.
We have a catalog item,where we have a field Remove Manager .So whenever the user selects any manager who needs to be removed ,it should be removed from the group table as well.How can we achieve this.
Groups table:
Thanks in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 04:15 AM
Hi @Kaustubh k ,
You can use below script to remove the selected manager from the filed.
var gr = new GlideRecord('sys_user_group');
gr.addEncodedQuery('name=Help Desk');
gr.query();
if (gr.next()) {
var inputString = gr.u_group_manager; // Replace with your actual field
var valueToRemove = 'fe82abf03710200044e0bfc8bcbe5d18,d64b9bd783095210a9589780deaad3c6'; // The value you want to remove
var remv = valueToRemove.split(',');
var array = inputString.split(',');
for (var i = 0; i < remv.length; i++) {
var valueToRemoveTemp = remv[i];
// Filter out the value to remove
var filteredArray = array.filter(function(item) {
return item.trim() !== valueToRemoveTemp.trim();
});
// Join the array back into a string
var updatedString = filteredArray.join(',');
array=filteredArray;
}
// Split the string into an array
gs.print(array);
}
You can use business rule to write the above code. I have tested it in background script, its working.
You just need to set "array" to your "u_group_manager" field.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 04:15 AM
Hi @Kaustubh k ,
You can use below script to remove the selected manager from the filed.
var gr = new GlideRecord('sys_user_group');
gr.addEncodedQuery('name=Help Desk');
gr.query();
if (gr.next()) {
var inputString = gr.u_group_manager; // Replace with your actual field
var valueToRemove = 'fe82abf03710200044e0bfc8bcbe5d18,d64b9bd783095210a9589780deaad3c6'; // The value you want to remove
var remv = valueToRemove.split(',');
var array = inputString.split(',');
for (var i = 0; i < remv.length; i++) {
var valueToRemoveTemp = remv[i];
// Filter out the value to remove
var filteredArray = array.filter(function(item) {
return item.trim() !== valueToRemoveTemp.trim();
});
// Join the array back into a string
var updatedString = filteredArray.join(',');
array=filteredArray;
}
// Split the string into an array
gs.print(array);
}
You can use business rule to write the above code. I have tested it in background script, its working.
You just need to set "array" to your "u_group_manager" field.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP
-------------------------------------------------------------------------