
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 07-13-2018 12:00 PM
Update: Resolve button widget article - https://community.servicenow.com/community?id=community_article&sys_id=13e89bb9db7fbfc8d82ffb2439961...
I keep seeing questions about Reopening Incident widget that requires comments from end user while reopening incident so I decided to write this article on how to create reopen widget.
Create Widget with below 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</button>
<div ng-if="data.response1" class="alert alert-info">{{::data.response1}}</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");
// Valid GlideRecord
var gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
//Button Visibility
if(data.table == 'incident' && gr.active == true && (gr.incident_state == 6 || gr.incident_state == 7) && (gr.caller_id == gs.getUserID() || gr.opened_by == gs.getUserID())){
data.showWidget = true;
data.showReopen = true;
} else {
data.showWidget = false;
data.showReopen = false;
}
//input
if (input && input.action === 'reopen') {
// If Incident table
if (data.table == 'incident') {
gr.setValue('incident_state', 1);
gr.setValue('state', 1);
gr.setValue('assigned_to', '');
gr.comments = "Ticket reopened. \nReopened with comments: "+ input.reopenComments;
gr.update();
}
}
})();
Client controller
function ($uibModal, $scope, spUtil) {
var c = this;
$scope.$on('record.updated', function(name, data) {
if(c.data.action == 'reopen'){
c.data.action = undefined;
}
spUtil.update($scope);
});
c.Reopen = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
spUtil.addInfoMessage("Incident has been Reopened", 3000);
c.modalInstance.close();
});
};
c.openModalReopen = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplateReopen',
scope: $scope
});
};
c.closeModal = function() {
c.modalInstance.close();
};
}
Template
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Provide a reason to Reopen Ticket</h4>
</div>
<div class="panel-body wrapper-xl">
<form name="modalTemplateReopen" ng-submit="c.Reopen('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="overflow: hidden; word-wrap: break-word; resize: horizontal;"></textarea>
</div>
<input class="btn btn-primary" type="submit" />
</form>
</div>
</div>
Screenshots:
Once Widget is created add it to tickets page.
Open Page Designer >Select Ticket Form page (ticket)
Drag and drop widget
Note: Widget will only appear on Resolved Incident
Final Result:
Disclaimer: I got started with code from somewhere so I don't own any rights.
- 16,548 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
thank you so much Mike.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
What would it take to modify this code to work as an escalate button? Meaning the same button appears but gives the customer the option to change the priority to High or Critical?
Just curious as we are looking for a way to perform that action..

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
It is easy to do.
you can add like
<button type="button" class="btn btn-secondary btn-block" ng-click="c.escalate()" ng-if="data.showEscalate">Escalate</button>
c.escalate = function() {
c.data.action = 'escalate';
c.server.update().then(function() {
c.data.action = undefined;
spUtil.addInfoMessage("Incident has been updated", 3000);
});
};
//Button Visibility
if(data.table == 'incident' && gr.active == true && (gr.incident_state == 6 || gr.incident_state == 7) && (gr.caller_id == gs.getUserID() || gr.opened_by == gs.getUserID())){
data.showWidget = true;
data.showReopen = true;
data.showEscalate = false;
} else {
data.showWidget = true;
data.showReopen = false;
data.showEscalate = true;
}
if (input && input.action === 'escalate') {
// If Incident table
if (data.table == 'incident') {
if(gr.urgency == 3){
gr.setValue('urgency', 2);
}else if(gr.urgency == 2){
gr.setValue('urgency', 1);
}else if(gr.urgency == 1){
data.showEscalate = false;
data.showWidget = false;
}
gr.comments = "Ticket Updated.";
gr.update();
}
}

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you, this is great. I added it into the widget but the escalate part does not work. The button appears as Escalate but it does not respond when clicked. However, it does convert to re-open as expected.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Below worked for me.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Make sure user has access to change urgency field on INC record.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mike.
2 things... first, thank you very much for this as it's a great wee widget! Second thing is a minor issue - I wanted to add a Cancel button (for users that didn't realise ESC got you out of it) so I added in the following line to the template, just before the Submit button -
<button class="btn btn-default" ng-click="c.closeModal()">Cancel</button>
I don't really know what I'm doing, I'm just trying random stuff and seeing what happens and the above got me to roughly where I want to be! However there are 2 trivial issues with my heuristic solution - one is that I can't see how to align the Submit button to the right, and also pressing Cancel briefly shows the "This is a required field" message before closing the form. If you can tell me the PROPER solution for what I'm trying to achieve I'd much appreciate it!
Edit: Actually it works even less well than I thought! If I type in the box and click Cancel it reopens the call!
Edit 2: I gave up on the cancel button! I took out the panel-heading bit and added the following at the start of the template (it adds a traditional x close button at the top right of the modal -
<div class="modal-header">
<button type="button" class="close" datadismiss="modal" aria-hidden="true" ng-click="$dismiss()">×</button>
<h3 class="panel-title">Please provide a comment to reopen incident</h3>
</div>
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thankyou mike article helped me alot
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Mike,
We want the same thing for Requests and as well as for Incident tickets.
Visibility - Button should be visible when sla breaches
Functionality - Upon escalation , user should provide reason for escalation and those comments should be added to additional comments and priority should raise to high/critical.
I am not good at scripting but can follow steps easily. Any help will be appreciated.
Thanks in advance
Regards.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This code works fine for me. But I need to fetch different field value based on that Reopen button will work.
Please refer this link: https://community.servicenow.com/community?id=community_question&sys_id=666e54d7db64449014d6fb243996193e
I need the solution asap.
Thanks!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
excellent this fulfills my requirement thank you so much
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I was able to get a button to work plus the X button in the corner thanks to your help. Here's what ended up working well for me:
<div class="panel panel-default">
<div class="modal-header" class="panel-heading">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" ng-click="$dismiss()">×</button>
<h4 class="panel-title">Please provide a reason for reopening:</h4>
</div>
<div class="panel-body wrapper-md">
<form name="modalTemplateReopen" ng-submit="c.Reopen('reopen')">
<div class="form-group">
<textarea required sp-autosize="true" ng-required="true" ng-model="data.reopenComments"
id="reopenComments" placeholder="Comments are 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: vertical;"></textarea>
</div>
<div class="text-right">
<button type="button" class="btn btn-default" style="margin-right: 15px;" data-dismiss="modal"
ng-click="$dismiss()">Cancel</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
So I tried creating this Widget and while it is visible on the portal, when I click the Reopen Widget button on a Resolved state incident, I get the following error
Attaching a doc with screen shot of the widget and template

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Based on your screenshot looks like your template ID is ModalTemplateReopen instead of modalTemplateReopen
m needs to be lowercase since whole code is based on it.
Change M to m and it should work.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mike,
Need some help on the duration field on Service Portal. I have cloned form widget and trying to retrieve hours and minutes for validation.
Since, I cannot use getelementbyid in Service Portal. How can I access those values?
Any help is appreciated.
<input type="text" class="form-control ng-valid ng-dirty ng-valid-parse ng-not-empty ng-touched"
id="dur-hours-u_start_date_of_activity" ng-model="parts[unit]" ng-disabled="field.isReadonly()"
ng-change="updateDuration()" title="Hours" role="textbox" aria-invalid="false" style="">
<input type="text" class="form-control ng-pristine ng-untouched ng-valid ng-not-empty"
id="dur-minutes-u_start_date_of_activity" ng-model="parts[unit]" ng-disabled="field.isReadonly()"
ng-change="updateDuration()" title="Minutes" role="textbox" aria-invalid="false">
Thanks,
Ashraf
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mike,
Thanks a ton it helped me alot. Very much appreciated your post.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
In Rome you need to edit the standard ticket pages and actions etc or you need to direct the tickets to the old page.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Mike! Not sure you will see this comment as I see this article is fairly old. First of all, thank you for this, it seems exactly like what I am looking for. Second, I seem to be doing something wrong: i am currently on Quebec, went to service portal - widgets, create new. I have followed the above instructions, but nothing appears on the service portal.
As per your instructions, after this i went to the portal editor
Do you know what am I missing?
Thanks!
Marta

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes, It's old but it should work on Quebec. Instead of checking on Widget Editor Open incident like below
https://XXXXXX.service-now.com/sp?id=ticket&sys_id=a83820b58f723300e7e16c7827bdeed2&table=incident
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Mike
Thank you for the quick reply!! Unfortunately this is what i see

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Make sure to change sys_id of incident to one of your instance incident sys_id.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello,
Tried, same result unfortunately!
(this is the link used https://grandvision.service-now.com/sp?id=ticket&sys_id=04dbd0af1ba9c110c37020a1b24bcbd2bdeed2&table=incident)
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
It didn't work for me in Rome either. I did as Charles said, edit the standard ticket page. I added the modal and the functions inside the "Incident Standard Ticket Actions" widget instead on creating a custom widget for it.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Manual,
I am not following your comment. Any chance you can provide some screenshots of what you did to get this to work?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Charles,
Can you provide screenshots of what you did to get this to work for Rome?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Does anyone know if this works in San Diego?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I have not
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mr. @Mike Patel good day!
I came across this post and I'm just wondering how we can incorporate the same behavior to Employee Center Portal?
Our current setup in Employee Center portal does not have a reopen button when the INC is Resolved. And we want users to be able to reopen an incident that will also requires comments.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mike,
This article helped me a lot but wanted to have drop down instead of a pop up window when clicked on reopen button with choices in it.Could you please help me here.