I want to set the email address in the variable set as the CC of the notification email.

SS68
Tera Contributor

Prepare the multi-line variable set (MRVS) "cc_users" in the Service Catalog.
The variable set "cc_users" contains the variable "user_email".
A user sets up multiple email addresses in the "cc_users" form in the Service Catalog.
You want to add these email addresses to the CC of the email notifying the user that the Service Catalog (e.g. the Catalog that creates the RITM) has been processed.
I am trying, but when I look at the actual email notifying users, the CC field remains empty.
How should I write an Email script?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@SS68 

so basically you have a MRVS and it contains a variable which holds email and you want to include those users in cc of email?

I would suggest you make the user_email as reference variable rather than single line text

If that's correct you need to use email script and something like this, please enhance

(function runMailScript(current, template, email, email_action, event) {

	// Add your code here

	var jsonString = current.variables.cc_users;

	var parsedData = JSON.parse(jsonString);

	for(var i=0;i<parsedData.length;i++){
		email.addAddress("cc", parsedData[i].user_email, parsedData[i].user_email);
	}

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@SS68 

so basically you have a MRVS and it contains a variable which holds email and you want to include those users in cc of email?

I would suggest you make the user_email as reference variable rather than single line text

If that's correct you need to use email script and something like this, please enhance

(function runMailScript(current, template, email, email_action, event) {

	// Add your code here

	var jsonString = current.variables.cc_users;

	var parsedData = JSON.parse(jsonString);

	for(var i=0;i<parsedData.length;i++){
		email.addAddress("cc", parsedData[i].user_email, parsedData[i].user_email);
	}

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader