Why gs.eventQueue not working?

Ankita Kolhe
Tera Contributor

Hi community,

My requirement is to trigger the notifications to customer admins when any Blocked by record is created for their related accounts.

I'm triggering event through gs.eventQueue() but it's not working.Although logs are priniting the values fine.

Below is the BR:-

 

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

// Add your code here
var contacts=[];
gs.info('account: ' + current.blocked_task.account.getDisplayValue());

var gr = new GlideRecord('customer_contact');
gr.addQuery('account', current.blocked_task.account);
gr.query();

while (gr.next()) {
gs.info('sys_id: '+gr.sys_id);
var gr1 = new GlideRecord('sys_user_has_role');
gr1.addQuery('user', gr.sys_id);
gr1.addQuery('role','9b94fc24d7700200e5982cf65e610358');
gr1.query();

gs.info('no: '+gr1.getRowCount());
while (gr1.next()) {
gs.info('cust admin role: '+gr1.user.getDisplayValue());
contacts.push(gr1.user);
}

}
gs.info('admins: '+contacts);
for(i=0;i<contacts.length;i++){
gs.eventQueue('blocked_by_event_registry',current,contacts[i],gs.getUserID()) ;
}
})(current, previous);

 

find_real_file.png

find_real_file.png

3 REPLIES 3

Musab Rasheed
Tera Sage
Tera Sage

Hi @Ankita Kolhe ,

You have not defined i hence seeing issue just define var i in for loop like below.

for(var i=0;i<contacts.length;i++)

 

if still doesn't work then replace code like this

Replace

for(var i=0;i<contacts.length;i++){
gs.eventQueue('blocked_by_event_registry',current,contacts[i],gs.getUserID()) ;
}

with

for(var i=0;i<contacts.length;i++){

emailTo = contacts[i];
gs.eventQueue('blocked_by_event_registry',current,emailTo ,gs.getUserDisplayName()) ;

 

Mark my answer as correct or hit like based on impact.

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi Musab,

Thanks for the response.

It's working now. The event name was incorrectIt should be sn_customerservice.blocked_by_event_regi.

Ok cool , you didn't declared i as well right.? anyways mark answer as correct and close the thread.

Please hit like and mark my response as correct if that helps
Regards,
Musab