Send an email to user from variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 01:58 AM
Hello,
I have catalog item which has variable called "Contact Person". I have created notification and I want this notification to be populated with following users:
To: should be populated with user from Contact Person variables
CC: should be populated with any delegate that Contact Person set + person who raised a request
How this could be achieved?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 03:51 AM
Thanks, @Maddysunil. Is this a mail script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 03:58 AM
@Dawid2 This script you can use it in workflow run script. Do you need mail script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 04:00 AM
Yeah, I think mail script would be more useful to me 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 04:25 AM
You can write something like below in the mail script
// Get the value of the 'Contact Person' variable
var contactPerson = current.variables.contact_person; // Update 'contact_person' with the actual variable name
// Get the user record for the 'Contact Person'
var contactPersonUser = new GlideRecord('sys_user');
if (contactPersonUser.get('user_name', contactPerson)) {
// Construct the 'To' recipient list with the 'Contact Person'
var to = contactPersonUser.email.getDisplayValue();
// Get the delegate for the 'Contact Person' (if any)
var delegate = contactPersonUser.getValue('u_delegate');
// Get the user record for the person who raised the request
var requestedByUser = new GlideRecord('sys_user');
if (requestedByUser.get(current.opened_by)) {
if (delegate)
email.addAddress('cc', new GlideRecord('sys_user').get('user_name', delegate).email.getDisplayValue());
email.addAddress(‘cc’, new GlideRecord('sys_user').get('sys_id', current.opened_by).email.getDisplayValue());
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks