Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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
Mega 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

Chaitanya ILCR
Mega 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