code transfer

Shaik Imran
Tera Contributor
<table style="width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; border: 1px solid rgb(136, 136, 140);">
  <tbody>
    <!-- Table Title -->
    <tr>
      <td colspan="2" style="background-color: rgb(126, 128, 126); color: white; font-size: 1.5em; font-weight: bold; padding: 8px; border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 15.0pt;">Critical Incident Communication</span>
      </td>
    </tr>
    <!-- Priority Banner -->
    <tr>
      <td colspan="2" style="background-color: ${mail_script:im_cic_priority_color}; color: ${mail_script:im_cic_priority_textcolor}; font-weight: bold; padding: 4px; border: 1px solid #88888c; border-top: none;">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">Priority ${mail_script:im_cic_priority}</span>
      </td>
    </tr>
    <!-- Incident hyperlink (WHITE row, no shading) -->
    <tr>
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140); padding: 4px;">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">${URI_REF}</span>
      </td>
    </tr>
    <!-- Priority (gray row) -->
    <tr style="background-color: rgb(201, 201, 201);">
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Priority:</span> ${priority}
        </span>
      </td>
    </tr>
    <!-- Start (white row) -->
    <tr>
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Start:</span> ${u_outage_start}
        </span>
      </td>
    </tr>
    <!-- Resolved (gray row) -->
    <tr style="background-color: rgb(201, 201, 201);">
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Resolved:</span> ${u_outage_end}
        </span>
      </td>
    </tr>
    <!-- Duration (white row) -->
    <tr>
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Duration:</span> ${mail_script:im_cic_duration}
        </span>
      </td>
    </tr>
    <!-- Systems Impacted (gray row) -->
    <tr style="background-color: rgb(201, 201, 201);">
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Systems Impacted:</span> ${mail_script:im_cic_getAffectedProducts}
        </span>
      </td>
    </tr>
    <!-- Description (white row) -->
    <tr>
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Description:</span> ${u_cic_description}
        </span>
      </td>
    </tr>
    <!-- Impact to Clients (gray, full width) -->
    <tr style="background-color: rgb(201, 201, 201);">
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Impact to our Clients:</span> ${u_external_impact}
        </span>
      </td>
    </tr>
    <!-- Impact to Employees (white, full width) -->
    <tr>
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Impact to our Employees:</span> ${u_internal_impact}
        </span>
      </td>
    </tr>
    <!-- Cause (gray, full width) -->
    <tr style="background-color: rgb(201, 201, 201);">
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Cause:</span> ${u_probable_cause}
        </span>
      </td>
    </tr>
    <!-- Completed Actions (white, full width) -->
    <tr>
      <td colspan="2" style="border: 1px solid rgb(136, 136, 140);">
        <span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">
          <span style="font-weight: bold;">Completed Actions<br></span> ${u_previous_activities}
        </span>
      </td>
    </tr>
  </tbody>
</table>
15 REPLIES 15

Shaik Imran
Tera Contributor
(function runMailScript(current, template, email, email_action, event) {
    var table = '';
    table += '<table style="width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; border: 1px solid rgb(136,136,140);"><tbody>';

    // Title Row
    table += '<tr><td colspan="2" style="background-color: rgb(126,128,126); color: white; font-size: 1.5em; font-weight: bold; padding: 8px; border: 1px solid rgb(136,136,140);"><span style="font-family: Aptos, sans-serif; font-size: 15.0pt;">Critical Incident Communication</span></td></tr>';

    // Priority Banner    
    table += '<tr><td colspan="2" style="background-color: ' + prioritybgcolor(current) + '; color: ' + prioritytextcolor(current) + '; font-weight: bold; padding: 4px; border: 1px solid #88888c; border-top: none;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">' + incpriority(current) + '</span></td></tr>';

    // Incident Number/Hyperlink Row (alternating color will be handled with row count logic)    
    var colorToggle = false; // start with white after banners    
    table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;">${URI_REF}</span></td></tr>';
    colorToggle = !colorToggle;

    table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Priority:</span> ' + current.priority.getDisplayValue() + '</span></td></tr>';
    colorToggle = !colorToggle;

    table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Start:</span> ' + current.u_outage_start + '</span></td></tr>';
    colorToggle = !colorToggle;

    if (email_action.event_name.getDisplayValue() != 'im_cic_new') {
        if (!current.u_outage_end.nil()) {
            table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Resolved:</span> ' + current.u_outage_end + '</span></td></tr>';
            colorToggle = !colorToggle;
        }

        var duration = '';
        if (!current.u_outage_start.nil() && !current.u_outage_end.nil()) {
            duration = calcDiff(current.u_outage_start.getDisplayValue(), current.u_outage_end.getDisplayValue());
            table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Duration:</span> ' + duration + '</span></td></tr>';
            colorToggle = !colorToggle;
        }
    }

    var aff = '';
    aff = getAffectedProducts(current.sys_id);
    table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Systems Impacted:</span> ' + aff + '</span></td></tr>';
    colorToggle = !colorToggle;

    table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Description:</span> ' + current.u_cic_description + '</span></td></tr>';
    colorToggle = !colorToggle;

    if (email_action.event_name.getDisplayValue() != 'im_cic_new') {
        if (!current.u_external_impact.nil()) {
            table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Impact to our Clients:</span> ' + current.u_external_impact + '</span></td></tr>';
            colorToggle = !colorToggle;
        }
        if (!current.u_internal_impact.nil()) {
            table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Impact to our Employees:</span> ' + current.u_internal_impact + '</span></td></tr>';
            colorToggle = !colorToggle;
        }
        if (!current.u_probable_cause.nil()) {
            table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Cause:</span> ' + current.u_probable_cause + '</span></td></tr>';
            colorToggle = !colorToggle;
        }
    }
    if (email_action.event_name.getDisplayValue() != 'im_cic_new' && email_action.event_name.getDisplayValue() != 'im_cic_update') {
        if (!current.u_resolution_activities.nil()) {
            table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Resolution Activities:</span> ' + current.u_resolution_activities + '</span></td></tr>';
            colorToggle = !colorToggle;
        }
    }

    if (email_action.event_name.getDisplayValue() == 'im_cic_update' || email_action.event_name.getDisplayValue() == 'sno.im.cic.restore.verify') {
        if (!current.u_previous_activities.nil()) {
            table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Completed Actions:</span> ' + current.u_previous_activities + '</span></td></tr>';
            colorToggle = !colorToggle;
        }
    }
    if (email_action.event_name.getDisplayValue() == 'im_cic_pis') {
        if (!current.u_previous_activities.nil()) {
            table += '<tr' + (colorToggle ? ' style="background-color: rgb(201,201,201);"' : '') + '><td colspan="2" style="border: 1px solid rgb(136,136,140); padding: 4px;"><span style="font-family: Aptos, sans-serif; font-size: 12.0pt;"><span style="font-weight: bold;">Action Items:</span> ' + current.u_action_items + '</span></td></tr>';
            colorToggle = !colorToggle;
        }
    }

    table += '</tbody></table>';
    template.print(table);

    function prioritybgcolor(current) {
        var bgcolor = '';
        var bgpriority = current.priority + '';
        if (email_action.event_name.getDisplayValue() == 'im_cic_pis') bgcolor = '#00b050';
        else if (bgpriority == '2') bgcolor = '#C00000';
        else if (bgpriority == '3') bgcolor = '#E97132';
        else if (bgpriority == '4') bgcolor = '#FFFF66';
        return bgcolor;
    }

    function prioritytextcolor(current) {
        var textcolor = '';
        var textpriority = current.priority + '';
        if (email_action.event_name.getDisplayValue() == 'im_cic_pis') textcolor = '#FFFFFF';
        else if (textpriority == '2') textcolor = '#FFFFFF';
        else if (textpriority == '3') textcolor = '#FFFFFF';
        else if (textpriority == '4') textcolor = '#000000';
        return textcolor;
    }

    function incpriority(current) {
        var priority = current.priority;

        if (email_action.event_name.getDisplayValue() == 'im_cic_pis') {
            return "Post Incident Summary";
        } else if (priority == 2) {
            return "Priority 1";
        } else if (priority == 3) {
            return "Priority 2";
        } else if (priority == 4) {
            return "Priority 3";
        }
    }

    function calcDiff(start, end) {
        var durr = gs.dateDiff(start, end, false);
        durr = durr.toString().replace(/:/g, ' ').split(' ');
        var duration = '';
        switch (durr.length) {
            case 1:
                duration = durr[0] + ' Seconds.';
                break;
            case 2:
                duration = durr[0] + ' Minutes ' + durr[1] + ' Seconds.';
                break;
            case 3:
                duration = durr[0] + ' Hours, ' + durr[1] + ' Minutes ' + durr[2] + ' Seconds.';
                break;
            case 4:
                duration = durr[0] + ' Days, ' + durr[1] + ' Hours, ' + durr[2] + ' Minutes ' + durr[3] + ' Seconds.';
                break;
        }
        return duration;
    }

    function getAffectedProducts(current) {
        var pdct = [];
        var gr = new GlideRecord("task_ci");
        gr.addQuery('task', current);
        gr.query();
        while (gr.next()) {
            if (!gr.ci_item.u_tla.nil()) {
                pdct.push(gr.ci_item.u_tla.getDisplayValue());
            }
        }
        pdct = pdct.sort();
        pdct = pdct.toString();

        //add spaces to the string for readability 
        pdct = pdct.replace(/,/g, ', ');
        return pdct;
    }


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