- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2018 01:25 AM
Hi Team,
I am trying to enable a cancel request option from Service portal. Have created a widget for this and introduced a button. I would like to redirect to requests page once user click (Button)/cancels the request.
Below are my code snippet.
HTML
<div>
<div class="panel panel-primary">
<div class="panel-heading">Actions</div>
<div class="panel-body">
<button type="button" class="btn btn-default btn-block" ng-click="c.uiAction('cancel')">Cancel</button>
</div>
</div>
</div>
Client Side
function($scope, spUtil) {
var c = this;
spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
});
}
}
Server side
(function() {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
//gs.addInfoMessage(data.table);
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
data.request_state = gr.getValue('request_state');
data.ShowCancel = (data.request_state == "requested") ? true : false;
if (input && input.action) {
var action = input.action;
// If Incident table
if (data.table == 'sc_request') {
if (action == 'cancel') {
gr.request_state="closed_cancelled";
gr.state="Closed Incomplete";
gr.stage="closed_incomplete";
gr.update();
gs.addInfoMessage('Request was cancelled.');
//gs.setRedirect('/sp?id=requests');
}
}
}
})();
Please let me know how can i achieve this?
Thanks
Sri.
Solved! Go to Solution.
- Labels:
-
Request Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2018 01:42 AM
Hi,
You will write like this in client-side script.
function($scope, spUtil) {
var c = this; spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
location.href="id=<page_id>"
});
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2018 01:42 AM
Hi,
You will write like this in client-side script.
function($scope, spUtil) {
var c = this; spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
location.href="id=<page_id>"
});
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2018 01:50 AM
Thank you it worked, i had tried this before, was not sure what i missed it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2023 01:26 AM
is their is any way to achieve same thing using server script