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.

How to send the mrvs variables details with table format

Brahmi Pandla
Tera Guru

Hi Everyone,

I have a requirement to send the notification with MRVS variables details when the user submit the request

 

below  are the variables

BrahmiPandla_0-1745480311758.png

i am looking for email script, could you please help anyone with script 

2 REPLIES 2

Tushar
Kilo Sage
Kilo Sage

Hi @Brahmi Pandla  - something like this -

(function runMailScript(current, template, email, email_action, event) { // Get the MRVS data from the current sc_req_item record var mrvs = current.variables.travel_details; // add your MRVS internal name

// if MRVS has data
if (mrvs) {
    // stored as JSON string
    var rows = JSON.parse(mrvs);
    
    // Check rows
    if (rows.length > 0) {
        template.print('<b>Travel Details:</b><br>');
        template.print('<table border="1"><tr><th>Departure Location</th><th>Arrival Location</th><th>Departure Date</th></tr>');
        
       
        for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
            // Access the variables using their internal names
            var departureLocation = row.departure_location || '-';
            var arrivalLocation = row.arrival_location || '-';
            var departureDate = row.departure_date || '-';
            
            // Add row to the table
            template.print('<tr><td>' + departureLocation + '</td><td>' + arrivalLocation + '</td><td>' + departureDate + '</td></tr>');
        }
        
        template.print('</table><br>');
    } else {
        template.print('<b>Travel Details:</b> No travel details provided.<br>');
    }
} else {
    template.print('<b>Travel Details:</b> No travel details provided.<br>');
}

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

 

Thanks.

Hi Tushar,

 

Thanks for your response

is it possible to  call email script in work flow notification activity?