Service Portal Reopen Incident Widget

Wes Farmer
Kilo Contributor

So I have created an Reopen Incident widget based largely on the Resolve Incident widget from ServiceNow Elite (http://www.servicenowelite.com/blog/2017/5/12/service-portal-resolve-incident-button ).   It's basically doing the same thing, except it sets incident state back to Active and updates the Additional Comments Journal field.   It works great, HOWEVER, it is behaving inconsistently where it will usually make duplicate entries into the Additional Comments sometimes 2, 3, or 4 duplicates and sometimes correctly enters just once with no rhyme or reason.   I am curious if anyone else has seem this behavior.   Code is below.

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>

<div class="panel panel-default">

<div class="panel-heading">

<h4 class="panel-title">Provide a reason for the reopening</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="overflow: hidden; word-wrap: break-word; resize: horizontal;"></textarea>

</div>

<input class="btn btn-primary" type="submit" />

</form>

</div>

</div>

</script>

Server Script

(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;

//Button Visibility

if(data.table == 'incident' && gr.active == true && gr.incident_state == 6 && gr.caller_id == gs.getUserID()){

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', 2);

gr.setValue('state', 2);

//gr.setValue('resolved_by', gs.getUserID());

gr.comments = "Reopened by caller with comment: " + input.reopenComments;

gr.update();

//data.response1 = gs.getMessage('Incident '+gr.number+' was resolved');

}

}

}

})();

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();

}

}

12 REPLIES 12

Did you test this in IE (any version?)



Im testing this. Difference between browsers is that Chrome leaves the button as submit, but IE the button text shows up as "Submit query"



Did you notice this behavior ?


Nevermind this statement. I added the bold section to the HTML and its gone now.



<input class="btn btn-primary" type="submit" value="Submit"/>


You just need   to update ($scope.$on) your client script to below;



$scope.$on('record.updated', function(name, data) {


if(c.data.action == 'reopen'){


c.data.action = undefined;


}


spUtil.update($scope);


});


Thanks Mike


Hi Mike,

I do have the same requirement to be done. Do you mean to say as per your above comment that the entire Client Script needs to be changed.

Suggested by wesfarmer:

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();

}

}

 

Suggested by Mike

 

$scope.$on('record.updated', function(name, data) {

 

if(c.data.action == 'reopen'){

 

c.data.action = undefined;

 

}

 

spUtil.update($scope);

 

});

 

 

Please kindly suggest?

 

Thanks,

SNOW@Das