Call Script include from Business Rule

hongsok
Tera Contributor

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();

 

1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @hongsok 

update your BR script

var x = new u_removeRolesGroupsFromUser();
x.removeGroups(current.getValue('sys_id'));
this.updateUserRecord(user, group); //where is this updateUserRecord method definition? in
 
 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@hongsok 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, it is not working.

@hongsok 

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?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Business is on the sys_user table condition is

hongsok_0-1742317597813.png