how add option in button active in the portal ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 07:54 AM
The cancellation button in the portal will be see and available to the user only if the fault status is "new".
The status will change to "cancelled" and the closing code will be canceled by the customer
please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 10:54 AM
Hi @Yahav Mor ,
To add the Cancel option, you can follow the steps bellow.
1. Open the script include: "IncidentUtils"
You'll be able to extend the Class of IncidentUtilsSNC, adding your new function 'canCancelIncident' within the IncidentUtils. For this function you should add the condition for the "Cancel" option be available, below I added the condition to be available, so that the Cancel option is only available if the state is new ( you might want to restrict this functionality for some roles as well, if that is the case you should need add this condition )
var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(IncidentUtilsSNC, {
initialize: function() {
IncidentUtilsSNC.prototype.initialize.call(this);
},
/***************Custom changes****************/
canCancelIncident: function(current) {
return current.incident_state == IncidentState.NEW;
},
type: 'IncidentUtils'
});
2. Next, you'll need to add the functionality to your widget. For that, navigate to Service Portal > Widgets
Open the " Incident Standard Ticket Actions"
And make the following modifications to the code
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:void(0)" ng-click="$event.stopPropagation();resolveIncident()">${Resolve}</a>
</li>
<li ng-if="data.canReopen">
<a href="javascript:void(0)" ng-click="$event.stopPropagation();reopenIncident()">${Reopen}</a>
</li>
<li ng-if="data.canCancel">
<a href="javascript:void(0)" ng-click="$event.stopPropagation();cancelIncident()">${Cancel}</a>
</li>
<li ng-if="data.canClose">
<a href="javascript:void(0)" ng-click="$event.stopPropagation();closeIncident()">${Close}</a>
</li>
</ul>
</div>
</div>
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;
incidentGr.work_notes="Incident Cancelled"; // here you can add any update that you'd like to do to incident ticket, in this case adding a work note that says incident cancelled
data.isIncidentCancelled = 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.canClose = incidentUtils.canCloseIncident(incidentGr);
data.canCancel=incidentUtils.canCancelIncident(incidentGr);
data.showActions = data.canResolve || data.canReopen || data.canClose || data.canCancel;
}
data.i18n = {};
})();
If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know
Cheers