How do I use a services user list to send a notification to all of them?

Bidduam
Tera Guru

So what I want to do is I thought somewhat simple and it might be, but not for me currently lol

 

I have a list of services, each service has a bunch of users associated with each one. What I want to be able to do is to send an email notification to the list of users for whichever service has been selected.

 

I have a catalog item with a reference field called u_service which is using the cmdb_ci_service table. I want the notification to send at a point in the flow to all users associated with the selected service.

 

This is what I mean by users associated:

Bidduam_0-1721951027503.png

 

 

Anyone able to help me please, with actual instructions for my exact situation - I've looked at different forum chats already and found a heap, none of them are exactly what I want to do and I can't adapt them to do what I need either.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Hi @Bidduam 

My above approach is for scripting part. You can refer to below for flow designer in your scenario.

1. Firstly, there should be a step to get catalog variable.

Timi_0-1722237580380.png

 

2. Then come to the Fire Event step.

Timi_1-1722237682554.png

 

Script

var service = fd_data._1__get_catalog_variables.u_service_affected; //call your variable from the 1st step
var users = [];
var gr = new GlideRecord('m2m_sp_status_subscription'); //your relationship table
gr.addQuery('cmdb_ci_service', service);
gr.query();
while(gr.next()){
	users.push(gr.getValue('sys_user'));
}
return users;

 

Cheers,

Tai Vu

View solution in original post

6 REPLIES 6

Tai Vu
Kilo Patron
Kilo Patron

Hi @Bidduam 

Let give the following steps a try to send a notification to multiple users associated with a service.

1. Define an Event Registry

2. Define a Notification triggered when the event is fired and the Event parm 1 contains recipient enabled.

3. Query the relationship table to collect all associated users.

4. Fire the event where you want to send the notification.

Sample script below.

var users = [];
var gr = new GlideRecord('m2m_sp_status_subscription'); //your relationship table
gr.addQuery('cmdb_ci_service', <your_service_variable>); //your variable
gr.query();
while(gr.next()){
	users.push(gr.getValue('sys_user'));
}
if(users.length > 0){
	gs.eventQueue('sc.catalog.notf.service_users', current, users); //replace your event name and the current RITM record.
}

 Event queue:

Timi_0-1721967041103.png

Mail log:

Timi_1-1721967052885.png

 

Cheers,

Tai Vu

@Tai Vu thank you for your reply, I get most of what you are suggesting I do to make this work and what I have tried to do with your recommendation is:

  1. Added a new event to the event registry called - art.notify.send
  2. The service variable name I'm using is - u_service_affected
  3. I've created a flow that at a certain point creates a new event record:
    Bidduam_0-1722225699973.png

     

  4. I've created a notification that is triggered by the event - art.notify.send
  5. I added the script you offered to the advanced section of the notification (thinking this is not the right place, but not sure what the right place would be - catalog client script of the catalog item?)
    Bidduam_1-1722225959664.png

    Script:

 

var users = [];
var gr = new GlideRecord('m2m_sp_status_subscription'); //your relationship table
gr.addQuery('cmdb_ci_service', 'variables.u_service_affected'); //your variable
gr.query();
while(gr.next()){
	users.push(gr.getValue('sys_user'));
}
if(users.length > 0){
	gs.eventQueue('art.notify.send', current, users); //replace your event name and the current RITM record.
}

 

  • I do also have Parm1 selected.

Unfortunately, this is not working at all - Ideas? Further guidence?

thank you 🙂

Hi @Bidduam ,

 

  1. Added a new event to the event registry called - art.notify.send

For the above point, you don't need to create flow for it. As this need to be created once only.

So, Navigate to [sysevent_register] table and create with the name 'art.notify.send'

SN_Learn_0-1722227481424.png

 

2. The catalog Item which you are using is having a flow or workflow?

If a workflow is attached to it, then you have to use the 'create event' activity

SN_Learn_1-1722227943371.png

 

SN_Learn_2-1722227991735.png

 

Script for parm1:

(function() {
    var users = [];
    var gr = new GlideRecord('m2m_sp_status_subscription');
    gr.addQuery('cmdb_ci_service', current.variables.u_service);
    gr.query();
    while (gr.next()) {
        users.push(gr.getValue('sys_user'));
    }
    return users;
}());

 

This will trigger the event and recipient in parm1

SN_Learn_3-1722228038104.png

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

@SN_Learn thanks for the help.

 

I am using flow designer (not workflow editor), so what I have is a flow step to create the event that is in the event registry - art.notify.send

 

The create event is as follows:

Bidduam_0-1722229947023.png

When it runs the following message shows in the execution details:

Error: Cannot read property "variables" from null,Detail: Cannot read property "variables" from null

 

I also have tried it without current.variables in front of the variable name and it doesn't error but parm1 is then blank