Send notification to email addresses in Multi-Row Variable set

AnetaR
Tera Contributor

Hi, I'm quite new to SN scripting so would appreciate your help on the below.

 

On a record producer I have a very simple MRVS with just one column for email addresses (they are external to our user db hence I cannot grab them from the system). 

 

For the sake of excercise let's agree that:

* the Internal Name of the MRVS is 'mrvs_name'

* the email variable on the MRVS is 'mrvs_email'

 

How can I grab the emails submitted in the MRVS into the recipients field on the notification?

 

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage
Mega Sage

@AnetaR Trigger notification using the gs.eventQueue function and pass the recipient in the parm.

 

Documentation for gs.eventQueue function: https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/c_GlideSystemScopedAPI

 

to get email in mvrs in business rule you can have below code.

 

var mvrs = current.variables.mrvs_name;

mvrs = JSON.parse(mvrs);

 

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

gs.info(mvrs[i].mrvs_email);

//you can call the gs.eventQueue function here

}

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

8 REPLIES 8

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @AnetaR ,

Please check the below link which will help to write the script for MVRS.

https://www.servicenow.com/community/developer-blog/scripting-the-multi-row-variable-set/ba-p/227495...

Bascially, you need to get the Variable and JSON parse that values in client script once you do it. You can pass the values in script include and trigger the notification via event. Where your event parameter will be values parsed i.e email id.

In this way you can try to achieve this requirement.

 

Thank you,

Omkar

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Hello @AnetaR ,

Can you please mark this correct. So that the thread will be closed.

Thanks,

Omkar

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

jaheerhattiwale
Mega Sage
Mega Sage

@AnetaR Trigger notification using the gs.eventQueue function and pass the recipient in the parm.

 

Documentation for gs.eventQueue function: https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/c_GlideSystemScopedAPI

 

to get email in mvrs in business rule you can have below code.

 

var mvrs = current.variables.mrvs_name;

mvrs = JSON.parse(mvrs);

 

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

gs.info(mvrs[i].mrvs_email);

//you can call the gs.eventQueue function here

}

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hi,

I have a similar requirement to send notification to emails which are in multivariable set.

I followed the steps as you mentioned , but notifications are triggering ,

 

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

// Add your code here

var mvrs = current.variables.emailaddress;
gs.log('email---'+ mvrs);
mvrs = JSON.parse(mvrs);
for (var i = 0; i < mvrs.length; i++)
{
gs.log(mvrs[i].customer_supplier);
gs.log('mvrs---'+mvrs[i]);

gs.eventQueue('SendMailToSupplier/Customer', current, current.variables.customer_supplier, '');
gs.log('event working');

}

})(current, previous);

 

NeelavathiM_0-1675312667251.png

 

I think some logic is missing ,but i could not rectify it can you please help me .

Thanks in Advance.