We have a BR removes inactive group manager with a new one, what is the new group manager Variable?

Nicholas Hromya
Giga Guru

Hello all,

 

We have a notification that fires on the BR created event below.  The notification has the group and the old manager removed, I am trying to find the variable that shows the new manager this BR replaced.  We want one notification that says <old manager> removed and replaced with <new manager> in this <group name>.

 

I am trying to find the new manager variable to put in the notification.  Else a new way to do this? 

 

The BR from Solved: Re: Auto remove inactive managers from active grou... - ServiceNow Community

The BR is:

sys_user that says

before Insert

condition current.active.changesTo('false')

var group = new GlideRecord('sys_user_group');

group.addQuery('manager', current.sys_id);

group.query();

while(group.next()){

group.manager = current.manager;

group.update();

gs.eventQueue('group.manager.changed', group, group.manager, current.name);}

var grmember = new GlideRecord('sys_user_grmember');

grmember.addQuery('user', current.sys_id);

grmember.query();

while(grmember.next()){

grmember.deleteRecord();

}

Thanks

Nick

1 ACCEPTED SOLUTION

Chaitanya ILCR
Mega Patron

Hi @Nicholas Hromya ,

step 1

create a event in the event registry (name= group.manager.changed and table = sys_user_group)

ChaitanyaILCR_0-1767889798868.png

 

2. create a BR 

ChaitanyaILCR_1-1767889981729.png

script ( i have slightly modified the script)

(function executeRule(current, previous /*null when async*/ ) {

    var group = new GlideRecord('sys_user_group');

    group.addQuery('manager', current.sys_id);

    group.query();

    while (group.next()) {

        group.manager = current.manager;

        group.update();

        gs.eventQueue('group.manager.changed', group, current.manager.name, current.name);
    }

    var grmember = new GlideRecord('sys_user_grmember');

    grmember.addQuery('user', current.sys_id);

    grmember.query();

    while (grmember.next()) {

        grmember.deleteRecord();

    }

})(current, previous);

 

3 create a notification

 

ChaitanyaILCR_2-1767890065415.png

ChaitanyaILCR_3-1767890133772.png

 

u can use the ${event.parm1} for the new manager and ${event.parm2} for the old manager name

 

 

you can customize the notification content as per you need 

 

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

Regards,
Chaitanya

 

View solution in original post

3 REPLIES 3

Chaitanya ILCR
Mega Patron

Hi @Nicholas Hromya ,

step 1

create a event in the event registry (name= group.manager.changed and table = sys_user_group)

ChaitanyaILCR_0-1767889798868.png

 

2. create a BR 

ChaitanyaILCR_1-1767889981729.png

script ( i have slightly modified the script)

(function executeRule(current, previous /*null when async*/ ) {

    var group = new GlideRecord('sys_user_group');

    group.addQuery('manager', current.sys_id);

    group.query();

    while (group.next()) {

        group.manager = current.manager;

        group.update();

        gs.eventQueue('group.manager.changed', group, current.manager.name, current.name);
    }

    var grmember = new GlideRecord('sys_user_grmember');

    grmember.addQuery('user', current.sys_id);

    grmember.query();

    while (grmember.next()) {

        grmember.deleteRecord();

    }

})(current, previous);

 

3 create a notification

 

ChaitanyaILCR_2-1767890065415.png

ChaitanyaILCR_3-1767890133772.png

 

u can use the ${event.parm1} for the new manager and ${event.parm2} for the old manager name

 

 

you can customize the notification content as per you need 

 

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

Regards,
Chaitanya

 

Thank you for replying.

I do see your 

gs.eventQueue('group.manager.changed', group, current.manager.name, current.name);

Is different than ours as 

gs . e v e n t q u e ue ('group.manager.changed', group, group.manager, current.name);
 
When the event triggers, it was only showing the parm2 as the old group manager.
I will try this and see.
Thank you!

Ankur Bawiskar
Tera Patron

@Nicholas Hromya 

so what debugging did you do?

where are you stuck?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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