Sandeep Kumar6
Giga Guru

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: find_real_file.png

Reopen Button:

find_real_file.png 

Comments: 

find_real_file.png

 

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 : 

<p style="font-family: Helvetica; color: black;">Dear ${caller_id},</p>
<p style="font-family: Helvetica; color: black;">Below Incident has been resolved. Please check for the details below</p>
<table style="width: 80%; background-color: #f2f2f2;">
<tbody>
<tr>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black; font-weight: bold;">Incident Number :</td>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black;" colspan="6">${number}</td>
</tr>
<tr>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black; font-weight: bold;">State:</td>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black;" colspan="6">${state}</td>
</tr>
<tr>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black; font-weight: bold;">Configuration Item:</td>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black;" colspan="6">${cmdb_ci}</td>
</tr>
<tr>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black; font-weight: bold;">Short Description :</td>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black;" colspan="6">${short_description}</td>
</tr>
<tr>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black; font-weight: bold;">Description :</td>
<td style="font-family: Helvetica; border: thin solid #C0C0C0; color: black;" colspan="6">${description}</td>
</tr>
</tbody>
</table>
<p>${mail_script:<Email Script Name>}</p>
<p>&nbsp;</p>

 

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('<p><font size="3" color="black" face="helvetica">');
template.print(gs.getMessage('Please click below button to go to Incident'));
template.print('</font></p>');
template.print('<font face="helvetica">');
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('<a href="' + link + '"');
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('</a>');
template.print('</font>');
template.print('<br><br>');
template.print('<p><font size="3" color="black" face="helvetica">');
template.print('</font></p>');
template.print('<p><font size="3" color="black" face="helvetica">');
template.print('Thank you.');
template.print('</font></p>');
})(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 :


<button type="button" class="btn btn-primary btn-block" ng-show="data.reopen" ng-click="c.openModal('reopen')">Re-Open Incident</button>

<script>
<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>
</script>

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
});
}

c.openModalResolve = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate',
scope: $scope
});
}

c.closeModal = function() {
$scope.data.action = "reopen";
$scope.data.reopenReason = $scope.data.reopenComments;
$scope.server.update().then(function(){
$scope.data.action = undefined;
$scope.data.reopenReason = "";
$scope.data.reopenIncFromMail = false;
});
if(!$scope.data.reopenComments){
alert("Please provide the reason to reopen the Incident.");
}
else
{
c.modalInstance.close();
}
};

}

 

Please Hit like and provide your feedback comment if this helped you.

Reference Link :

 

https://www.servicenowelite.com/blog/2017/5/12/service-portal-resolve-incident-button

https://community.servicenow.com/community?id=community_article&sys_id=db298e11db97d380fece0b55ca96195f

https://serviceportal.io/create-custom-action-buttons-service-portal/

 

Regards

Sandeep

 

Comments
Sneha Agase
Kilo Contributor

Hi Sandeep,

 

Your article helped alot. but can you please let me know the changes I need to do without email link but from portal directly. I am trying to add comments from portal where i am stuck. can you please help me with it.

The requirement i have is to reopen the incident from portal with comments mandatory.

JOHN133
Giga Expert

Hi Sandeep,

Your article helped me a lot, I am going to add another code that can help to create the reopen button which only appears when the incident is closed, it is very similar but you can try with this code

Regards

 

HTML Template

<div class="panel panel-primary b" ng-if="data.state=='6'">
<!-- panel-{{::c.options.color}} -->
<div class="panel-heading">
<p> Do you want to reopen your ticket?</p>
<h4 class="panel-title" ng-if="c.data.state == 'reopen'">Reopen Incident</h4>
</div>
<div class="panel-body">
<button type="submit" name="reopen" class="btn btn-default btn-question" ng-click="c.action('reopen_action')">${Reopen}</button>
</div>
</div>

 

Client Script

function ($scope, $window, spModal) {
var c = this;

c.action = function(state) {

if( (c.data.comments == undefined || c.data.comments == '' )&& state == 'reopen_action')spModal.prompt("What is the reason for the Reopening?").then(function(newComments) {
c.data.state = state;
c.data.comments = newComments;
c.server.update();
});

else {
c.data.state = state;
c.data.action = false;
c.server.update();
}
};
}

 

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;
}

data.state=gr.getValue('state');

if (input && input.reopen) {

gs.addInfoMessage('Ticket opening was successful');
// If Incident table
if (data.table == 'incident') {
// Resolve Incident
gr.setValue('incident_state', 2);
gr.setValue('state', '2');
gr.comments = "Ticket reopened with the comment:: "+ input.comments;
gr.update();
}
}

})();

JOHN133
Giga Expert

Hi Sneha.

you can try with code below

Regards

Version history
Last update:
‎05-02-2019 01:10 AM
Updated by: