Getting RITM number and short description into survey mail notification

RBlor
Mega Guru

I am having trouble with setting up a survey mail notification email script for a RITM request that shows the short description and RITM number I would love assistance if anyone is available. So this is an notification fired from the assessment table i believe and needs to know the target of the survey which is a Request Item: 

 

 

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template, /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, /* Optional GlideRecord */ event) {
    
    // Initialize variables for the related request item's number and short description
    var requestNumber = '';
    var requestShortDescription = '';

    // Check if the current assessment record has a related request item via the correct reference field
    if (current.u_request_item) { // Replace 'u_request_item' with the actual reference field name
        var requestGR = new GlideRecord('sc_req_item'); // Query the Request Item table
        if (requestGR.get(current.u_request_item)) {  // Retrieve the related Request Item record
            requestNumber = requestGR.getValue('number');  // Retrieve the request item number
            requestShortDescription = requestGR.getValue('short_description');  // Retrieve the short description
        }
    }

    // Start the email body
    template.print('<p><font size="3" color="#000000" face="calibri">');
    template.print(gs.getMessage('Hello,'));
    template.print('</font></p>');

    // Add the request number and short description to the email
    if (requestNumber && requestShortDescription) {
        template.print('<p><font size="3" color="#000000" face="calibri">');
        template.print(gs.getMessage('Request Number: ') + requestNumber);
        template.print('</font></p>');

        template.print('<p><font size="3" color="#000000" face="calibri">');
        template.print(gs.getMessage('Short Description: ') + requestShortDescription);
        template.print('</font></p>');
    } else {
        template.print('<p><font size="3" color="#000000" face="calibri">');
        template.print(gs.getMessage('Request details are not available.'));
        template.print('</font></p>');
    }

    // Continue with the rest of the email content
    template.print('<p><font size="3" color="#000000" face="calibri">');
    template.print(gs.getMessage('We have recently resolved your IT New Hire request.'));
    template.print('</font></p>');

    // Example button link for survey
    var ess = gs.getProperty("glide.servlet.uri") + 'people_operations?id=take_survey&instance_id=' + current.sys_id;
    template.print('<a href="' + ess + '" style="background-color: #FCC000; border: 1px solid #FCC000; color: #ffffff; font-size: 16px; font-family: calibri; text-decoration: none; border-radius: 3px; display: inline-block; padding: 5px;">');
    template.print(gs.getMessage('Take me to the Survey'));
    template.print('</a><br>');

    // End the email body
    template.print('<p><font size="3" color="#000000" face="calibri">');
    template.print(gs.getMessage('Thank you for taking the time to share your experience and feedback.'));
    template.print('</font></p>');
    
    template.print('<p><font size="3" color="#000000" face="calibri">');
    template.print(gs.getMessage('Vituity Service Desk'));
    template.print('</font></p>');

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

 

 

 

 

1 REPLY 1

Akash4
Kilo Sage
Kilo Sage

Hello,

On which table are executing this, incase it is sc_request then you do not have field for RITM. Meaning the line -

 if (current.u_request_item) { // Rep

will not work.

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.