- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 09:39 AM
Hello friend,
How can I call the script include from the Business Rule. I created the following script include and BR (condition is when active = false) and it is not working.
Script Include: var u_removeRolesGroupsFromUser = Class.create(); u_removeRolesGroupsFromUser.prototype = { initialize: function() { }, removeGroups: function(user) { //Query Group Membership table, loop through all groups and remove them the from User's profile var group = []; var gm2m = new GlideRecord('sys_user_grmember'); gm2m.addQuery('user', user); gm2m.query(); while(gm2m.next()) { //as each group is being added to the array, delete that group so no duplicates are displayed in the user record log. group.push(gm2m.group.name); gm2m.deleteRecord(); } this.updateUserRecord(user, group); }, type: 'u_removeRolesGroupsFromUser' }; |
Business Rule: var x = new u_removeRolesGroupsFromUser(); x.removeGroups(); |
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 10:16 AM
Hi @hongsok
update your BR script
var x = new u_removeRolesGroupsFromUser();
x.removeGroups(current.getValue('sys_id'));
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 09:46 AM
try this
Business Rule: -> I assume it's on sys_user table
var x = new u_removeRolesGroupsFromUser(current.sys_id);
x.removeGroups();
Script Include:
var u_removeRolesGroupsFromUser = Class.create();
u_removeRolesGroupsFromUser.prototype = {
initialize: function() {},
removeGroups: function(user) {
//Query Group Membership table, loop through all groups and remove them the from User's profile
var group = [];
var gm2m = new GlideRecord('sys_user_grmember');
gm2m.addQuery('user', user);
gm2m.query();
while (gm2m.next()) {
//as each group is being added to the array, delete that group so no duplicates are displayed in the user record log.
group.push(gm2m.group.name.toString());
gm2m.deleteRecord();
}
this.updateUserRecord(user, group);
},
type: 'u_removeRolesGroupsFromUser'
};
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
03-18-2025 10:00 AM
Hi Ankur, it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 10:03 AM
you didn't share exact details, business rule is on which table?
Didn't share screenshots of Business rule configuration
Didn't share logs which you added for debugging? what's your analysis for it?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 10:06 AM
Business is on the sys_user table condition is