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

vermaamit16
Kilo Patron

Hi @Dawid2 

 

Any particular reason to use Notification for this requirement ? You can easily do it with a Flow. You can create a flow with trigger type as Service Catalog and then make use of Get Catalog Variables action to get catalog variables and then make use of Send Email action to send the email.

 

If you still want to continue with notification, then you need to write an email script for that. You need to get the RITM variables inside your email script and then set the To and CC based on that. Finally, you need to call this email script from your notification.

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

I'd love to go with Flows but we're still using Workflows, that's why I opted for standard notification.

Maddysunil
Kilo Sage

@Dawid2 

You can utilize below sample 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)) {

        // Populate 'To' with the 'Contact Person'
        var toUser = contactPersonUser.user_name;

        // 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)) {

            // Populate 'CC' with the delegate and the person who raised the request
            var ccUsers = [];
            if (delegate)
                ccUsers.push(delegate);
            ccUsers.push(current.opened_by);

            // Add other CCs if needed

            // Trigger the notification with the populated 'To' and 'CC'
            gs.eventQueue('request.opened', current, requestedByUser.user_name, toUser, ccUsers);
        } else {
            gs.addErrorMessage('Failed to fetch user who raised the request.');
        }
    } else {
        gs.addErrorMessage('Failed to fetch Contact Person.');
    }

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks