Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Adding new option cancel under Actions on Incident Standard Ticket Actions widget

sanjeev20
Tera Contributor

Hi ,

 

We have added a new option i.e. Cancel under Action on Incident Standard Ticket Actions widget by customising the OOB widget. And its working fine i.e. when a user select this option the incident is getting cancelled. 

 

Can anyone suggests how I can open a modal window for a user to fill the cancellation reason when user is trying to cancel the incident.

HTML:

<div>
<div class="dropdown" id="child-case-tabs" ng-if="data.showActions">
<button type="button" id="actions-button" class="btn btn-default dropdown-toggle action-btn" data-toggle="dropdown" style="width : 100%" aria-haspopup="true" ng-init="setFocusOnActionButtons()">
${Actions}
<span class="fa fa-caret-down"></span>
</button>
<ul class="dropdown-menu pull-right" id="actionList">
<li ng-if="data.canResolve">
<a href="javascript&colon;void(0)" ng-click="$event.stopPropagation();resolveIncident()">${Resolve}</a>
</li>
<li ng-if="data.canReopen">
<a href="javascript&colon;void(0)" ng-click="$event.stopPropagation();reopenIncident()">${Reopen}</a>
</li>
<li ng-if="data.canClose">
<a href="javascript&colon;void(0)" ng-click="$event.stopPropagation();closeIncident()">${Close}</a>
</li>
<li ng-if="data.canCancel">
<a href="javascript&colon;void(0)" ng-click="$event.stopPropagation();cancelIncident()">${Cancel}</a>
</li>
</ul>
</div>

</div>

 

 

Client script:

function incidentTicketActions($scope, $http, spUtil, $timeout, spModal, i18n, $window, $uibModal, spAriaUtil) {
    /* widget controller */
    var c = this;
    c.doneLoading = false;
    c.resolvedIncidentMsg = "${Resolved Incident}";
    c.closedIncidentMsg = "${Closed Incident}";
    c.reopenedIncidentMsg = "${Reopened Incident}";
c.cancelIncidentMsg = "${Canceled Incident}";
 
 
    var MOBILE_DEVICE_SCREEN_WIDTH = 767;
    $scope.mobileDevice = c.data.isMobile || ($window.innerWidth < MOBILE_DEVICE_SCREEN_WIDTH);
 
$scope.resolveIncident = function() {
        $scope.data.action = 'resolveIncident';
        $scope.server.update(init).then(function(response){
if (response.isIncidentResolved)
spAriaUtil.sendLiveMessage(c.resolvedIncidentMsg);
});
$scope.$emit('focusOnActions', {"isFocusRequired": true});
    };
 
$scope.closeIncident = function() {
$scope.data.action = 'closeIncident';
        $scope.server.update(init).then(function(response){
if (response.isIncidentClosed)
spAriaUtil.sendLiveMessage(c.closedIncidentMsg);
});
var elm = document.getElementById('short-desc')
elm.focus();
};
 
    $scope.reopenIncident = function() {
        $scope.data.action = 'reopenIncident';
        $scope.server.update(init).then(function(response){
if (response.isIncidentReopened)
spAriaUtil.sendLiveMessage(c.reopenedIncidentMsg);
});
$scope.$emit('focusOnActions', {"isFocusRequired": true});
    };
$scope.cancelIncident = function() {
        $scope.data.action = 'cancelIncident';
        $scope.server.update(init).then(function(response){
                    if (response.isIncidentCanceled)
                        spAriaUtil.sendLiveMessage(c.cancelIncidentMsg);
                });
            $scope.$emit('focusOnActions', {"isFocusRequired": true});
    };
    function init() {}
 
    $(document).on('click', 'div.modal-footer button.btn, ul#child-case-tabs .dropdown-menu', function(e) {
        e.stopPropagation();
    });
 
    $(document).bind('dragover drop', function(event) {
        event.preventDefault();
        return false;
    });
 
    $scope.$on('sp_loading_indicator', function(e, value) {
        if (!value && !c.doneLoading) {
            c.doneLoading = true;
        }
    });
}
 
Server Script:
(function() {
    var incidentGr = new GlideRecord('incident');
var incidentSysId = options.sys_id;
 
if (!incidentSysId && $sp.getParameter('table') == 'incident')
incidentSysId = $sp.getParameter('sys_id');
 
if (!incidentSysId && $sp.getParameter('table') == 'universal_request') {
var urGr = new GlideRecord('universal_request');
urGr.get($sp.getParameter('sys_id'));
incidentSysId = urGr.primary_task + "";
}
 
/* Actions - Start */
    if (input && input.action == 'resolveIncident' && incidentGr.get(incidentSysId)) {
        incidentGr.incident_state = global.IncidentState.RESOLVED;
incidentGr.state = global.IncidentState.RESOLVED;
incidentGr.resolved_by = gs.getUserID();
data.isIncidentResolved = incidentGr.update();
    }
 
if (input && input.action == 'reopenIncident' && incidentGr.get(incidentSysId)) {
        incidentGr.incident_state = global.IncidentState.IN_PROGRESS;
incidentGr.state = global.IncidentState.IN_PROGRESS;
data.isIncidentReopened = incidentGr.update();
gs.addInfoMessage(gs.getMessage("Request reopened"));
    }
 
if (input && input.action == 'closeIncident' && incidentGr.get(incidentSysId)) {
incidentGr.incident_state = global.IncidentState.CLOSED;
incidentGr.state = global.IncidentState.CLOSED;
data.isIncidentClosed = incidentGr.update();
    }
 
if (input && input.action == 'cancelIncident' && incidentGr.get(incidentSysId)) {
        incidentGr.incident_state = global.IncidentState.CANCELED;
        incidentGr.state = global.IncidentState.CANCELED;
        data.isIncidentCanceled = incidentGr.update();
    }
   /* Actions - End */
 
/* Load incident data */
    if (incidentGr.get(incidentSysId)) {
var incidentUtils = new global.IncidentUtils();
data.canResolve = incidentUtils.canResolveIncident(incidentGr);
//data.canReopen = incidentUtils.canReopenIncident(incidentGr);
data.canReopen = incidentGr.state == '6';
data.canClose = incidentUtils.canCloseIncident(incidentGr);
    data.canCancel =  incidentGr.active == true && incidentGr.state < '6'  && (incidentGr.caller_id == gs.getUserID() || incidentGr.opened_by == gs.getUserID());
data.showActions = data.canResolve || data.canReopen || data.canClose || data.canCancel;
}
 
    data.i18n = {};
 
})();
1 REPLY 1

Community Alums
Not applicable

Hi Sanjeev,

I made the above changes and updated the widget in the standard ticket configuration but still the changes are not reflecting.

Do I need to update the new custom widget somewhere?