Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Send an email to user from variable

Dawid2
Giga Guru

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?

8 REPLIES 8

Thanks, @Maddysunil. Is this a mail script?

@Dawid2 This script you can use it in workflow run script. Do you need mail script?

Yeah, I think mail script would be more useful to me 🙂

@Dawid2 

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