How to create cancel request button on the service portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 11:02 PM
I need to add cancel request button on the portal so that when a user click on it, it cancels the REQ Item and go to cancelled state. Can someone help me with code?
Thanks in advance
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 11:23 PM
Hi,
check these links
Cancel request from Service Portal
How can I add a Cancel button on Service Portal ?
Allow Users to Cancel their INC or RITM/REQ in Service Portal
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2021 04:01 AM
Hi Ankur,
I have followed the above link,now i could see cancel request button on portal,but when i click on it,it is not working.
<div class="panel panel-default">
<div class="panel-heading">Actions</div>
<div class="panel-body">
<button type="button" name="cancel" class="btn btn-primary btn-question" ng-click="c.cancel()">Cancel Request</button>
</div>
Server side
(function() {
data.showNoAction = true;
data.showResolve = false;
data.showReopen = false;
data.showCancel = false;
data.showClose = false;
// 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;
var closed = IncidentState.CLOSED;
var canceled = IncidentState.CANCELED;
var resolved = IncidentState.RESOLVED;
var newState = IncidentState.NEW;
var on_hold = IncidentState.ON_HOLD;
var awaiting_caller = IncidentReason.AWAITING_CALLER;
var active = gr.active;
var state = gr.getValue('state');
var reason = gr.getValue('hold_reason');
if (state == resolved) {
data.showReopen = true;
data.showClose = true;
data.showNoAction = false;
}
if (state == newState || state == on_hold && reason == awaiting_caller) {
data.showResolve = true;
data.showCancel = true;
data.showNoAction = false;
}
if (input && input.action) {
var action = input.action;
// If Incident table
if (data.table == 'sc_req_item') {
if (action == 'resolve') {
// Resolve Incident
gr.setValue('state', resolved);
gr.setValue('state', resolved);
gr.setValue('resolved_by', gs.getUserID());
gr.update();
}
if (action == 'reopen') {
// Reopen Incident
gr.setValue('state', newState);
gr.setValue('state', newState);
gr.update();
}
if (action == 'close') {
// Close Incident
gr.setValue('state', closed);
gr.setValue('state', closed);
gr.update();
}
if (action == 'cancel') {
// Cancel Incident
gr.setValue('state', canceled);
gr.setValue('state', canceled);
gr.update();
}
}
}
})();
</div>
client side
function() {
var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2021 04:50 AM
Hi,
Are there any mandatory fields which needs to be set when you cancel the REQ?
Did you try adding logs in server side?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2021 06:15 AM
There are no any mandatory fields.
I didn't adding logs