logo

NJP

Reopen Incident Button on Service Portal from from Email Notification

Import · May 02, 2019 · article

This article is about reopening an incident from Service Portal.

Steps:

  • When anyone resolve Incident It will send Email to End User / Caller with the link of Incident (Service Portal) to reopen it.
  • End user who receive email If he has role then link will automatically redirected to Default Incident view otherwise it will go to Service Portal view.
  • End user has capability to reopen the incident from Service portal by providing comments.
  • Please follow below procedure and see the image below for demo.

Notification: image

Reopen Button:

image

Comments:

image

Create Your flow now All the best !!

Create Notification

Name : Any Suitable name

Table : Incident

When to Send : On Inset or Update : Update , Condition : State changes to Resolve

Who will receive : Caller

What it will contain :

Subject : Incident ${number} has been resolved

Message :

Dear ${caller\_id},

Below Incident has been resolved. Please check for the details below

Incident Number : ${number}
State: ${state}
Configuration Item: ${cmdb\_ci}
Short Description : ${short\_description}
Description : ${description}

${mail\_script:}

 

Create Email Script --- It will have link based on the role of end user.

Name: Any Suitable Name

Script:

(function runMailScript(current, template, email, email_action, event) {

// Check User Role to redirect to Service Portal

var hasRole = new GlideRecord('sys_user_has_role');

hasRole.addQuery('user', current.caller_id);

hasRole.query();

if (hasRole.next()) {

link = "https://"+gs.getProperty('instance_name') + ".service-now.com/incident.do?sys_id="+current.sys_id;

}

else

{

link = "https://"+gs.getProperty('instance_name') + ".service-now.com/sp?id=ticket_hfc&table=incident&sys_id="+current.sys_id;

}

// Code to take end user to the incident

template.print('

');

template.print(gs.getMessage('Please click below button to go to Incident'));

template.print('

');

template.print('');

var backgroundColor = 'background-color: #278efc;';

var border = 'border: 1px solid #0368d4;';

var color = 'color: #ffffff;';

var fontSize = 'font-size: 16px;';

var fontFamily = 'font-family: Helvetica, Arial, sans-serif;';

var textDecoration = 'text-decoration: none; border-radius: 3px;';

var webKitBorder = '-webkit-border-radius: 3px;';

var mozBorder = '-moz-border-radius: 3px;';

var display = 'display: inline-block;';

var padding = 'padding: 5px;';

template.print(' template.print('style="' + backgroundColor + border + color + fontSize + fontFamily + textDecoration + webKitBorder + mozBorder + display + padding);
template.print('">');

template.print(gs.getMessage('Take me to the Incident'));

template.print('
');

template.print('');

template.print('

');

template.print('

');

template.print('

');

template.print('

');

template.print('Thank you.');

template.print('

');

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

Create Button / Widget to reopen the incident on Service Portal.

Go to Navigation --> Service Portal --> Widget

Name: Any Suitable Name

Body HTML template :

Re-Open Incident

<div class="panel panel-default"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title">Provide a reason to Re-Open the Incident</h4> </div> <div class="panel-body wrapper-xl"> <form name="modalTemplate"> <div class="form-group"> <textarea required sp-autosize="true" ng-required="true" ng-model="data.reopenComments" id="reopenComments" placeholder="Comments required" class="form-control ng-pristine ng-valid ng-scope ng-empty ng-touched" aria-invalid="false" style="overflow: hidden; word-wrap: break-word; resize: horizontal;"></textarea> </div> <input class="btn btn-primary" ng-click="c.closeModal()" type="submit" /> </form> </div> </div> </div>

Server script :

(function() { // Get table & sys_id data.table = input.table || $sp.getParameter("table"); data.sys_id = input.sys_id || $sp.getParameter("sys_id");

data.reopen = true;

// Valid GlideRecord gr = new GlideRecord(data.table); if (!gr.isValid()) return; // Valid sys_id if (!gr.get(data.sys_id)) return; //Button Visibility if (gr.getValue('state') != 6){ data.reopen = false; data.flag = false; } if (input && input.action) { var action = input.action; // If Incident table if (data.table == 'incident') { if (action == 'reopen') { // Resolve Incident gr.setValue('incident_state', 2); gr.setValue('state', '2'); if(input.reopenComments) { gr.comments = "Ticket reopened with comments: "+ input.reopenComments; } gr.update(); } } } })();

Client controller:

function($uibModal, $scope, spUtil) {

var c = this;

$scope.$on('record.updated', function(name, data) {

c.data.reopenComments = '';

spUtil.update($scope);

})

c.openModal = function(action) {

c.data.action = action;

c.server.update().then(function() {

c.data.action = undefined;

})

c.modalInstance = $uibModal.open({

templateUrl: 'modalTemplate',

scope: $scope

});

}

View original source

https://www.servicenow.com/community/now-platform-articles/reopen-incident-button-on-service-portal-from-from-email/ta-p/2318616