Need to create a button i.e., reopen a button when case is closed
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2023 04:55 AM
I need to create a button through widget. I have a requirement where when a case is closed or incomplete or cancelled. I need to place a button where the user can click it and able to open the reopen the case.can anyone help with this
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2023 03:02 AM
Hi @Community Alums,
Below is the widget 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 Incident</button>
<div ng-if="data.response1" class="alert alert-info">{{::data.response1}}</div>
</div>
</div>
<script type="text/ng-template" id="modalTemplateReopen">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Let us know why you are reopening this incident</h4>
</div>
<div class="panel-body wrapper-xl">
<form name="modalTemplateReopen" ng-submit="c.uiAction('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="width:100%"></textarea>
</div>
<div class="modal-footer">
<button class="btn btn-info" style="width: 22%;" data-dismiss="{{myCol}}" ng-model="myCol" ng-click="myform.$valid &&
c.uiAction('reopen')">Ok</button>
<button type="button" class="btn btn-default" data-dismiss="modal" style="width: 22%;">Cancel</button>
</div>
</form>
</div>
</div>
</script>
Server Script: Change the table name and state accordingly.
(function() {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
var gdt = new GlideDateTime();
gdt.addDays(-2);
var date1 = gdt.getLocalDate();
console.log(date1);
console.log(gr.sys_updated_on);
console.log(gr.sys_updated_on <= date1);
//Button Visibility
if(data.table == 'incident' && (gr.state == 150)){
data.showWidget = true;
data.showReopen = true;
} else {
data.showWidget = false;
data.showReopen = false;
}
//input
if (input && input.action) {
var action = input.action;
// If Incident table
if (data.table == 'incident') {
if (action == 'reopen') {
//gr.setValue('incident_state', 1);
gr.setValue('state', 1);
//gr.setValue('resolved_by', gs.getUserID());
gr.comments = "Reopened with comment: " + input.reopenComments;
gr.update();
//data.response1 = gs.getMessage('Incident '+gr.number+' was resolved');
}
else if(action == 'cancel'){
}
}
}
})();
Client Controller:
function($uibModal, $scope, spUtil) {
var c = this;
$scope.$on('record.updated', function(name, data) {
spUtil.update($scope);
})
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
c.modalInstance.close();
}
c.openModalReopen = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplateReopen',
scope: $scope
});
}
c.closeModal = function() {
c.modalInstance.close();
}
}
You create this widget and add it to the ticket page.
Mark this answer as correct and helpful if it solves your issue.
Regards,
Siva Jyothi M.