send notification to MRVS variable(user) and List collector

si21
Tera Guru

Hi experts,

We have two requirements after submitting record producer to create a HR case

1. Send notification to user selected in Mutlirow variables set records on a record producer.

2. Send notification to all the users selected in a LIST collector variable on a record producer.

 

How can we achieve this.

 

TIA

2 ACCEPTED SOLUTIONS

Moin Kazi
Kilo Sage
Kilo Sage

Hi @si21 ,

 

  1. Multi-row Variable Set Notification:

    • Create a Business Rule that triggers after the record producer is submitted.
    • In the script, access the multi-row variable set:

 

var multiRow = current.variables.multi_row_variable; // Replace with your variable name
if (multiRow) {
    var userId = multiRow[0].user; // Access the user field from the first row
    if (userId) {
        // Send notification to the selected user
        gs.eventQueue('your.notification.event', current, userId, null);
    }
}

 

 

       2. LIST Collector Variable Notification:

  • In the same Business Rule, add code to handle the LIST collector variable

 

var listUsers = current.variables.list_collector_variable; // Replace with your variable name
if (listUsers) {
for (var i = 0; i < listUsers.length; i++) {
var user = listUsers[i];
// Send notification to each user
gs.eventQueue('your.notification.event', current, user, null);
}
}

 

 

In both examples, replace 'your.notification.event' with the actual notification event you’ve defined in ServiceNow.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.

 

Thank you!
Moin Kazi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

View solution in original post

Brad Bowman
Kilo Patron
Kilo Patron

You can do this in a Business Rule after Insert on the RP table.  To send to each user in an MRVS:

var mrvs = current.variables.mrvs_internal_name; //use your MRVS name
var rowCount = mrvs.getRowCount();
for (var i=0; i<rowCount; i++){
    var row = mrvs.getRow(i);
    gs.eventQueue('event.name', current, row.variable_name, null); //use your event name and MRVS variable name
}

And, to send to each user in a list collector variable:

var usrArr = current.variables.variable_name.toString().split(','); //use your list collector variable name
for (var j=0; j<usrArr.length; j++) {
    gs.eventQueue('event.name', current, usrArr[j], null); //use your event name
}

 

View solution in original post

10 REPLIES 10

can you share the code where you defined the event in the Business Rule and pic of notification where you have define event?

Hi @si21 ,

 

Can you try below code for list collector we need to split it before calculate the length- 

var listUsers = current.variables.list_collector_variable; // Replace with your variable name
var list = listUsers.split(',');
    if (list) {
        for (var i = 0; i < list.length; i++) {
            var user = list[i];
            // Send notification to each user
            gs.eventQueue('your.notification.event', current, user, null);
        }
    }

 

hope this help.

 

Regards,

Moin

Brad Bowman
Kilo Patron
Kilo Patron

You can do this in a Business Rule after Insert on the RP table.  To send to each user in an MRVS:

var mrvs = current.variables.mrvs_internal_name; //use your MRVS name
var rowCount = mrvs.getRowCount();
for (var i=0; i<rowCount; i++){
    var row = mrvs.getRow(i);
    gs.eventQueue('event.name', current, row.variable_name, null); //use your event name and MRVS variable name
}

And, to send to each user in a list collector variable:

var usrArr = current.variables.variable_name.toString().split(','); //use your list collector variable name
for (var j=0; j<usrArr.length; j++) {
    gs.eventQueue('event.name', current, usrArr[j], null); //use your event name
}

 

si21
Tera Guru

Hi @Moin Kazi / @Brad Bowman  , thank you so much for the help.

How can we access MRVS 'employee_name' variable inside the email notification body ?

si21_0-1729690137102.png

TIA

Hi @si21 ,

 

Update BR like below -

var listUsers = current.variables.list_collector_variable; // Replace with your variable name
var list = listUsers.split(',');
    if (list) {
        for (var i = 0; i < list.length; i++) {
            var user = list[i];
            var userName = new GlideRecord('sys_user');
	   userName.get(user);
            // Send notification to each user
            gs.eventQueue('your.notification.event', current, user,userName.name.toString());
        }
    }

In the html body use like - ${event.parm2}