notification in table format

Shaik Imran
Tera Contributor

How to create a notification in table format

15 REPLIES 15

Shaik Imran
Tera Contributor
<table style="width:100%; border-collapse:collapse; font-family:Arial,sans-serif;">
  <tr>
    <td colspan="2" style="background-color:#88888C; color:white; font-size:1.5em; font-weight:bold; padding:8px;">
      Critical Incident Communication
    </td>
  </tr>
  <tr>
    <td colspan="2" style="background-color:#d0021b; color:white; font-weight:bold; padding:6px;">
      Priority 1
    </td>
  </tr>
  <tr>
    <td colspan="2" style="padding-top:4px; padding-bottom:4px;">
      <a href="{incident_link}" style="color:#0066cc; text-decoration:underline;">{incident_number}</a> 
      <span style="color:#087a10; background-color:#b6f5bc; font-style:italic;">
        (We now want the Incident # hyperlinked to the record in SNO)
      </span>
    </td>
  </tr>
  <tr>
    <td style="font-weight:bold; width:130px;">Priority:</td>
    <td>1 – Critical <span style="color:#087a10; background-color:#b6f5bc;">{priority_change}</span></td>
  </tr>
  <tr>
    <td style="font-weight:bold;">Start:</td>
    <td>{start_time} <span style="color:#087a10; background-color:#b6f5bc;">{start_time_change}</span></td>
  </tr>
  <tr>
    <td style="font-weight:bold;">Resolved:</td>
    <td>{resolved_time} <span style="color:#087a10; background-color:#b6f5bc;">{resolved_time_change}</span></td>
  </tr>
  <tr>
    <td style="font-weight:bold;">Duration:</td>
    <td>{duration} <span style="color:#087a10; background-color:#b6f5bc;">{duration_change}</span></td>
  </tr>
  <tr>
    <td style="font-weight:bold;">Systems Impacted:</td>
    <td>{systems_impacted} <span style="color:#a88400; background-color:#fafd9b; font-style:italic;">(This should now be in alphabetical order)</span></td>
  </tr>
  <tr>
    <td style="font-weight:bold;">Description:</td>
    <td>{description} <span style="color:#087a10; background-color:#b6f5bc;">{description_change}</span></td>
  </tr>
  <tr>
    <td colspan="2" style="font-weight:bold; padding-top:12px;">
      Impact to our Clients:
    </td>
  </tr>
  <tr>
    <td colspan="2" style="font-size:0.99em;">
      {client_impact} 
      <span style="color:#a88400; background-color:#fafd9b; font-style:italic;">
        (Verbiage change "Impact to our Clients", however the place it comes from on the table remains the same...)
      </span>
    </td>
  </tr>
  <tr>
    <td colspan="2" style="font-weight:bold; padding-top:12px;">
      Impact to our Employees:
    </td>
  </tr>
  <tr>
    <td colspan="2" style="font-size:0.99em;">
      {employee_impact}
      <span style="color:#a88400; background-color:#fafd9b; font-style:italic;">
        (Verbiage change “Impact to our Employees”, however the place it comes from on the table remains the same...)
      </span>
    </td>
  </tr>
</table>

You, 13 min



(function runMailScript(current) {
  var priority = current.priority.getDisplayValue();
  var priColor = '#A7A8AA'; // default gray

  if (priority == '1 - Critical') {
    priColor = '#d0021b'; // red
  } else if (priority == '2 - High') {
    priColor = '#ED8B00'; // orange
  } else if (priority == '3 - Moderate') {
    priColor = '#FFD100'; // yellow
  } else if (priority == '4 - Low') {
    priColor = '#A7A8AA'; // gray
  }
  template.print('<g:priColor>' + priColor + '</g:priColor>');
})(current);

<table style="width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; border: 1px solid #88888c;">
<tbody><!-- Table Title -->
<tr>
<td style="background-color: #88888c; color: white; font-size: 1.5em; font-weight: bold; padding: 8px; border: 1px solid #88888c;" colspan="2">Critical Incident Communication</td>
</tr>
<!-- Priority Banner -->
<tr>
<td style="background-color: ${mail_script:prioritycolor}; color: white; font-weight: bold; font-size: 1.2em; padding: 8px; border: 1px solid #88888c; border-top: none;" colspan="2">Priority ${mail_script:Priority}</td>
</tr>
<!-- Incident hyperlink (WHITE row, no shading) -->
<tr>
<td style="border: 1px solid #88888c; padding: 4px;" colspan="2">${URI_REF}</td>
</tr>
<!-- Priority (gray row) -->
<tr style="background-color: #f2f2f2;">
<td style="border: 1px solid #88888c;"><span style="font-weight: bold;">Priority:</span> ${priority}</td>
</tr>
<!-- Start (white row) -->
<tr>
<td style="font-weight: bold; border: 1px solid #88888c;">Start:</td>
</tr>
<!-- Resolved (gray row) -->
<tr style="background-color: #f2f2f2;">
<td style="font-weight: bold; border: 1px solid #88888c;">Resolved:</td>
</tr>
<!-- Duration (white row) -->
<tr>
<td style="font-weight: bold; border: 1px solid #88888c;">Duration:</td>
</tr>
<!-- Systems Impacted (gray row) -->
<tr style="background-color: #f2f2f2;">
<td style="font-weight: bold; border: 1px solid #88888c;">Systems Impacted:</td>
</tr>
<!-- Description (white row) -->
<tr>
<td style="font-weight: bold; border: 1px solid #88888c;">Description:</td>
</tr>
<!-- Impact to Clients (gray, full width) -->
<tr style="background-color: #f2f2f2;">
<td style="font-weight: bold; border: 1px solid #88888c;">Impact to our Clients:</td>
</tr>
<!-- Impact to Employees (white, full width) -->
<tr>
<td style="font-weight: bold; border: 1px solid #88888c;">Impact to our Employees:</td>
</tr>
<!-- Cause (gray, full width) -->
<tr style="background-color: #f2f2f2;">
<td style="font-weight: bold; border: 1px solid #88888c;">Cause:</td>
</tr>
<!-- Resolution Activities (white, full width) -->
<tr>
<td style="font-weight: bold; border: 1px solid #88888c;">Resolution Activities:</td>
</tr>
</tbody>
</table>

(function executeRule(current, previous /*null when async*/ ) {
    // Variables to keep track of whether specific tasks have been created
    var alertTaskCreated = false;
    var resiliencyTaskCreated = false;
    var businessTaskCreated = false;

    var gr_problem_task_set = new GlideRecord('problem_task');
    gr_problem_task_set.addQuery('problem', current.sys_id.toString());
    gr_problem_task_set.query();

    // Check if either of the tasks below exist in this problem's tasks
    while (gr_problem_task_set.next()) {
        // Alerting / Monitoring problem task

        if (gr_problem_task_set.short_description == "Business Risk & Controls Technology Team review") {
            businessTaskCreated = true;
        }
        if (gr_problem_task_set.u_category == "Business Risk and Controls") {
            businessTaskCreated = true;
        }

    }

    // Create the Alerting / Monitoring Task
    if (!businessTaskCreated) {
        var today = new GlideDate();
        var dura = new GlideDuration(60 * 60 * 9 * 1000 * 30);
        var glides = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
        var end = glides.add(today, dura);


        var arr_date = [];
        arr_date = end.toString().split(' ');
        end_date = arr_date[0] + ' 17:00:00', 'yyyy-MM-dd HH:mm:ss';
        // gs.info("due date:" + end_date + end);


        var gr_problem_task = new GlideRecord('problem_task');
        gr_problem_task.initialize();
        gr_problem_task.cmdb_ci = current.cmdb_ci;
        gr_problem_task.assignment_group = "6fa377e0c37be210332ebe0bb00131d1";
        gr_problem_task.problem = current.sys_id.toString();
        gr_problem_task.state = 2; // Work in Progress
        gr_problem_task.short_description = "Business Risk & Controls Technology Team review";
        gr_problem_task.description = "Business Risk & Controls Technology Team review for TLA.";
        gr_problem_task.priority = 2;
        gr_problem_task.due_date = end_date;
        gr_problem_task.u_category = "Business Risk and Controls";
        gr_problem_task.insert();
    }


    // Query all problem tasks for the given problem
    var gr_problem_task_set_1 = new GlideRecord('problem_task');
    gr_problem_task_set_1.addQuery('problem', current.sys_id.toString());
    gr_problem_task_set_1.query();

    // Check if either of the tasks below exist in this problem's tasks
    while (gr_problem_task_set_1.next()) {
        // Alerting / Monitoring problem task
        if (gr_problem_task_set_1.short_description == "Determine if monitoring and/or alerting should be modified and/or created") {
            alertTaskCreated = true;
        }
        // Resiliency problem task
        if (gr_problem_task_set_1.short_description == "Perform a third-party resiliency review") {
            resiliencyTaskCreated = true;
        }
    }

    // Create the Alerting / Monitoring Task
    if (!alertTaskCreated) {
        var due_date = new GlideDateTime();
        due_date.addDaysUTC(15);

        var arr_date = [];

        arr_date = due_date.toString().split(' ');
        due_date.setDisplayValue(arr_date[0] + ' 17:00:00', 'yyyy-MM-dd HH:mm:ss');

        //STRY0284553 Edits - Changing Moogsoft CI sys_id to ServiceNow Event Management CI sys_id

        var gr_problem_task_1 = new GlideRecord('problem_task');
        gr_problem_task_1.initialize();
        // gr_problem_task.cmdb_ci = gr_cmdb_ci.sys_id.toString();
        // gr_problem_task.assignment_group = gr_sys_user_group.sys_id.toString();
        gr_problem_task_1.cmdb_ci = current.cmdb_ci;
        gr_problem_task_1.assignment_group = current.assignment_group;
        gr_problem_task_1.problem = current.sys_id.toString();
        gr_problem_task_1.state = 2; // Work in Progress
        gr_problem_task_1.short_description = "Determine if monitoring and/or alerting should be modified and/or created";
        gr_problem_task_1.description = "Determine if monitoring and/or alerting should be modified and/or created.";
        gr_problem_task_1.due_date = due_date;
        gr_problem_task_1.u_category = "Alerting/Monitoring";
        gr_problem_task_1.insert();
    }

    // Create the Third-Party Resiliency Review task
    // Cause Code must start with Vendor
    if (!resiliencyTaskCreated && current.u_cause_code.u_code.indexOf('Vendor') == 0) {

        // Create due date 30 days from now at 17:00
        var due_date = new GlideDateTime();
        due_date.addDaysUTC(30);
        var arr_date = [];
        arr_date = due_date.toString().split(' ');
        due_date.setDisplayValue(arr_date[0] + ' 17:00:00', 'yyyy-MM-dd HH:mm:ss');

        // Set assignment group to Business Continuity Management QA (sys_id below)
        //STRY0284553 Edits - Changing Assignment Group to Business Continuity Management QA Assignment Group
        var gr_sys_user_group = new GlideRecord('sys_user_group');
        gr_sys_user_group.get('09f055cb1b7ae1d49cb2657a234bcb72');

        // Create the new problem task record
        var gr_problem_task = new GlideRecord('problem_task');
        gr_problem_task.initialize();
        gr_problem_task.cmdb_ci = current.cmdb_ci;
        gr_problem_task.state = 2; // Work in Progress
        gr_problem_task.assignment_group = gr_sys_user_group.sys_id.toString();
        gr_problem_task.problem = current.sys_id.toString();
        gr_problem_task.short_description = "Perform a third-party resiliency review"; //STRY0284553 Edits- editing Short Description
        gr_problem_task.description = "Perform a third-party resiliency review for TLA.";
        gr_problem_task.due_date = due_date;
        gr_problem_task.u_category = "Business Continuity/Disaster Recovery Plan";
        gr_problem_task.insert();
    }

})(current, previous);

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    var color = '#88888c';
    var p = current.priority + '';
    if (p == '1') color = '#d0021b';
    else if (p == '2') color = '#f5a623';
    else if (p == '3') color = '#f8e71c';
    else if (p == '4') color = '#7ed321';
    else if (p == '5') color = '#4a90e2';
    template.print(color);
})(current, template, email, email_action, event);