- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 01:06 AM
Hello,
I am having requirement To update group names list on List field on employee profile form when a user is added or removed from the group, group names should automatically updated on list field value.
example,
->if user A is added to Group1 - then Group1 name should be updated on list field form.
-> when user A is removed from Group1 - then Group1 name should be removed and updated on list field on form
If anyone can help me on this would be helpful,
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 01:52 AM
you can use before delete business rule on sys_user_grmember table
Query your table and search if the user+group combination is present in your table
If yes then remove that group from list field
Something like this
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("your table"); // give your table name here
gr.addQuery("userField", current.user); // give your user field name here
gr.addQuery("groupField", "IN", current.group); // give your group field name here
gr.query();
if (gr.next()) {
var existingGroup = gr.groupField.toString(); // give your group field name here
var index = existingGroup.indexOf(current.group.toString());
if (index > -1) {
existingGroup.splice(index, 1);
}
gr.groupField = existingGroup.toString(); // set the groups again after removing the group
gr.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 01:52 AM
you can use before delete business rule on sys_user_grmember table
Query your table and search if the user+group combination is present in your table
If yes then remove that group from list field
Something like this
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("your table"); // give your table name here
gr.addQuery("userField", current.user); // give your user field name here
gr.addQuery("groupField", "IN", current.group); // give your group field name here
gr.query();
if (gr.next()) {
var existingGroup = gr.groupField.toString(); // give your group field name here
var index = existingGroup.indexOf(current.group.toString());
if (index > -1) {
existingGroup.splice(index, 1);
}
gr.groupField = existingGroup.toString(); // set the groups again after removing the group
gr.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 01:59 AM
Thanks for the response