Need to create reopen button on portal

charan_1
Tera Contributor

I need to create a reopen button on portal through widget for closed case. Can anyone help me with the script for this situation.

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@charan_1 

check this link has solution

Reopen Incident Button on Service Portal from from Email Notification 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Siva Jyothi M
Mega Sage

Hi @charan_1,

 

Below is the widget code.

HTML :

 

<div class="panel b" ng-if="data.showWidget">
<!--<div class="panel-heading bg-primary">Actions</div>-->
<div class="panel-body">
<button type="button" class="btn btn-success btn-block" ng-click="c.openModalReopen()" ng-if="data.showReopen">Reopen Incident</button>
<div ng-if="data.response1" class="alert alert-info">{{::data.response1}}</div>
</div>
</div>
 
 
<script type="text/ng-template" id="modalTemplateReopen">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Let us know why you are reopening this incident</h4>
</div>
<div class="panel-body wrapper-xl">
<form name="modalTemplateReopen" ng-submit="c.uiAction('reopen')">
<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="width:100%"></textarea>
</div>
<div class="modal-footer">
<button class="btn btn-info" style="width: 22%;" data-dismiss="{{myCol}}" ng-model="myCol" ng-click="myform.$valid &&
c.uiAction('reopen')">Ok</button>
<button type="button" class="btn btn-default" data-dismiss="modal" style="width: 22%;">Cancel</button>
</div>
</form>
</div>
</div>
</script>

 

 Server Script: Change the table name and state accordingly.

 

(function() {
 
 
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
 
 
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
 
 
// Valid sys_id
if (!gr.get(data.sys_id))
return;
 
var gdt = new GlideDateTime();
gdt.addDays(-2);
var date1 = gdt.getLocalDate();
 
	console.log(date1);
console.log(gr.sys_updated_on);
	console.log(gr.sys_updated_on <= date1);

//Button Visibility
if(data.table == 'incident' && (gr.state == 150)){
data.showWidget = true;
data.showReopen = true;
 
 
} else {
data.showWidget = false;
data.showReopen = false;
}
 
 
//input
if (input && input.action) {
var action = input.action;
 
 
// If Incident table
if (data.table == 'incident') {
if (action == 'reopen') {
//gr.setValue('incident_state', 1);
gr.setValue('state', 1);
//gr.setValue('resolved_by', gs.getUserID());
gr.comments = "Reopened with comment: " + input.reopenComments;
gr.update();
//data.response1 = gs.getMessage('Incident '+gr.number+' was resolved');
}
	else if(action == 'cancel'){
		
	}
}
}
})();

 

  Client Controller:

 

function($uibModal, $scope, spUtil) {
var c = this;
 
 
$scope.$on('record.updated', function(name, data) {
spUtil.update($scope);
})
 
 
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
c.modalInstance.close();
}
c.openModalReopen = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplateReopen',
scope: $scope
});
}
c.closeModal = function() {
c.modalInstance.close();
}
}

 

You create this widget and add it to the ticket page.

 

Mark this answer as correct and helpful if it solves your issue.

 

Regards,

Siva Jyothi M.