- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 05:40 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 11:37 PM
Hi @si21 ,
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 04:44 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 04:31 AM - edited 10-23-2024 04:31 AM
can you share the code where you defined the event in the Business Rule and pic of notification where you have define event?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 04:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 04:44 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 06:33 AM
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 ?
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:04 AM
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}