The CreatorCon Call for Content is officially open! Get started here.

Portal widget that add comments to incident is saving comment multiple times

alexbones
Tera Expert

Hello Community,

I'm working with a portal widget that adds a button to allows the caller to reopen an incident if its resolved. When they click the reopen button a input text box appears asking for a reason and when they submit it saves it as a comment. I am finding that on Istanbul instances it is saving the comment at least two times and sometimes three. I put the widget on a Jakarta or Kingston instance and it works just fine. Has anyone else every run into this issue? Currently the Prod instance is on Istanbul.

Reopen Comment.JPG

reopen comment- multiple times.JPG

Body HTML Template:

<div class="panel b" ng-if="data.showWidget || data.showWidgetReopen">

<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</button>

    <button type="button" class="btn btn-success btn-block" ng-click="c.openModalResolve()" ng-if="data.showResolve">Cancel</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 cancellation</h4>

</div>

<div class="panel-body wrapper-xl">

<form name="modalTemplateResolve" ng-submit="c.uiAction('cancel')">

<div class="form-group">

<textarea required sp-autosize="true" ng-required="true" ng-model="data.cancelComments" id="cancelComments" 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>

<script>

<div class="panel panel-default">

<div class="panel-heading">

<h4 class="panel-title">Provide a reason for reopening the 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="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() || gr.u_affected_user == gs.getUserID())){

data.showWidget = true;

data.showResolve = true;

} else {

data.showWidget = false;

data.showResolve = false;

}

//Reopen Button Visibility

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

data.showWidgetReopen = true;

data.showReopen = true;

} else {

data.showWidgetReopen = false;

data.showReopen = false;

}

//Input

if (input && input.action) {

var action = input.action;

// If Incident table

if (data.table == 'incident') {

if (action == 'cancel') {

gr.setValue('incident_state', 8);

gr.setValue('state', 8);

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

gr.setValue('close_notes','Cancelled by caller with comment: '+ input.cancelComments);

gr.setValue('close_code','Customer Cancelled');

gr.update();

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

}

if (action == 'reopen') {

gr.setValue('incident_state', 9);

gr.setValue('state', 9);

gr.setDisplayValue('comments', 'Reopened by caller with comment: '+ input.reopenComments);

//gr.setValue('comments','Reopened by caller with comment: '+ input.reopenComments);

gr.update();

}

}

}

})();

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.openModalResolve = function() {

c.modalInstance = $uibModal.open({

templateUrl: 'modalTemplateResolve',

scope: $scope

});

}

c.openModalReopen = function() {

c.modalInstance = $uibModal.open({

templateUrl: 'modalTemplateReopen',

scope: $scope

});

}

c.closeModal = function() {

c.modalInstance.close();

}

}

8 REPLIES 8

Hi Alex



Nice work!



Did you ever get anymore duplicate comments?   I have followed your fix and I still get a second comment added sometimes, except the user typed comment will not be in it (from c.data.reopenComments = ''; I assume)



Thanks


Yes mine is working now and only adding comments once.



Try also updating the server script last if statement that has action == 'reopen' to:


        if (action == 'reopen'&& input.reopenComments !='') {



Here is my full client script part of the widget:



function($uibModal, $scope, spUtil) {


      var c = this;


   


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


              c.data.reopenComments = '';


              spUtil.update($scope);


      })



      c.uiAction = function(action) {


              c.data.action = action;


              c.server.update().then(function() {


                      c.data.action = undefined;


              })


              c.modalInstance.close();


      }


      c.openModalResolve = function() {


              c.modalInstance = $uibModal.open({


                      templateUrl: 'modalTemplateResolve',


                      scope: $scope


              });


      }


      c.openModalReopen = function() {


              c.modalInstance = $uibModal.open({


                      templateUrl: 'modalTemplateReopen',


                      scope: $scope


              });


      }


      c.closeModal = function() {


              c.modalInstance.close();


      }


}




Davin Biggs
Tera Contributor

I'm trying out this solution, but the HTML keeps failing because of the <div> statements within the <script> statements.

What am I missing!  I've tried in both Jakarta and Kingston.

Cheers

Snow consultan1
Tera Contributor

Hi All,

 

I have the similar issue, can you please suggest me here.

 

https://community.servicenow.com/community?id=community_question&sys_id=3cccc8e4db5c6b84fff8a345ca96191c

 

Thanks for the help