Widget intermittently duplicating record updates

chrisp1
Mega Sage

Hi, wonder if anyone can assist with a custom widget which is doing the ticket update in the server script twice, but only intermittently and I cannot understand what is going on. I'm new to development and have based the code on the many helpful community posts, so may well be flawed!

I've tried the widget in a fresh dev instance (with the custom field created) and witness the same there.

Widget code as below any assistance greatly appreciated...

thanks in advance chris

HTML
<div>
<div class="panel panel-primary b" >
  <div class="panel-heading">
    <h4 class="panel-title pull-left">      
           ${Test actions}      
       </h4>
    <div class="clearfix"></div>
  </div>
 <div class="panel-body"> 
 <button type="button" class="btn btn-success btn-block" ng-click="c.Chase('chase')" ng-disabled="clicked" >Request update</button> 
</div></div></div>

Client script
function ($uibModal, $scope, spUtil, spModal) {
 var c = this;
 $scope.$on('record.updated', function(name, data) {
  spUtil.update($scope);
 });

c.Chase = function(action) {   
  $scope.clicked = true;
  c.data.action = action;
  c.server.update().then(function() {
   c.data.action = undefined;
   spUtil.addInfoMessage("An update has been Requested", 3000);
   spUtil.update($scope);
  }); }      }

Server script
(function() {
 data.table = input.table || $sp.getParameter("table");
 data.sys_id = input.sys_id || $sp.getParameter("sys_id");

  var gr = new GlideRecord(data.table);
 if (!gr.isValid())
  return;

 if (!gr.get(data.sys_id))
  return;
 
 if (input && input.action) {
 var action = input.action;

 if (action === 'chase') {
  var cc = gr.u_chase_call_counter;
  gr.u_chase_call_counter = cc+1;
  gr.comments = "An update has been requested";
 // gr.setWorkflow(false);
  gr.update();
 }  } })();

 

I tried gr.setWorkflow(false); but this just stopped the comments being posted to the record, the u_chase_call_counter still updated once/twice.

1 ACCEPTED SOLUTION

Justin77
Mega Guru

This is due to the spUtil.update($scope); call in your callback function.  In plain terms, what you're "c.Chase" is saying is, "run my server script, then once it's done, run the server script again".

View solution in original post

5 REPLIES 5

Justin77
Mega Guru

This is due to the spUtil.update($scope); call in your callback function.  In plain terms, what you're "c.Chase" is saying is, "run my server script, then once it's done, run the server script again".

Thanks Justin, removed it and seems to be working now

chrisp1
Mega Sage

Thanks Justin removing that has helped

Tanishka Arora1
Kilo Contributor

Can you please tell how you resolved this issue? I am facing the same problem 

Thanks