title: Update ServiceNow widget when updating a record
body: <p>I have a widget which displays records in a certain state, with a counter on top of how many there are (see image below). I want to update the counter when the user clicks on one of the buttons to reflect the current count.</p>
  <p>Part of my HTML:</p>
  <pre><code>&lt;div class=&quot;room-container&quot; ng-if=&quot;selectedRoom.sys_id&quot;&gt;
  &lt;div class=&quot;room-top-row&quot;&gt;
  
  &lt;!-- THIS IS THE PART I WANT TO UPDATE WHEN CLICKING THE BUTTONS --&gt;
    &lt;div class=&quot;room-title&quot;&gt;&lt;b&gt;{{selectedRoom.display}}&lt;/b&gt; ({{currentInventory.length}})&lt;/div&gt;
  
    &lt;input class=&quot;form-control item-scan-input&quot; type=&quot;text&quot; placeholder=&quot;${Scan item to inventory}...&quot; ng-model=&quot;scanInput&quot; ng-model-options=&quot;{debounce: 200}&quot; ng-change=&quot;updateInventoryScan(scanInput); scanInput='';&quot;&gt;
  &lt;/div&gt;
  
  
  &lt;table class=&quot;table table-striped&quot;&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;${Inventory Number}&lt;/th&gt;
      &lt;th&gt;${Inventory Type}&lt;/th&gt;
      &lt;th&gt;${Action}&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  
  &lt;tbody&gt;
    &lt;tr ng-repeat=&quot;inv in currentInventory&quot;&gt;
      &lt;td&gt;{{inv.inventory.display}}&lt;/td&gt;
      &lt;td&gt;{{inv.inventory.type}}&lt;/td&gt;
      &lt;td&gt;
          &lt;button ng-if=&quot;!inv.done&quot; class=&quot;btn btn-xs btn-primary&quot; ng-click=&quot;updateInventory(inv, 'inventoried', selectedRoom.sys_id)&quot;&gt;${Inventoried}&lt;/button&gt;
        &lt;button ng-if=&quot;!inv.done&quot; class=&quot;btn btn-xs btn-warning&quot; ng-click=&quot;updateInventory(inv, 'missing', selectedRoom.sys_id)&quot;&gt;${Missing}&lt;/button&gt;
        &lt;button ng-if=&quot;!inv.done&quot; class=&quot;btn btn-xs btn-danger&quot; ng-click=&quot;updateInventory(inv, 'will_be_scrapped', selectedRoom.sys_id)&quot;&gt;${Will Be Scrapped}&lt;/button&gt;
                  
        &lt;div ng-if=&quot;inv.done&quot; style=&quot;color: green;&quot;&gt;${Updated with state}: {{inv.state}}&lt;/div&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
    
     
    
  <p>Part of my Client script:</p>
  <pre><code>function($scope, $uibModal) {
  /* widget controller */
  var c = this;
  
  //----- Default Values -----
  $scope.selectedRoom = {};
  $scope.currentInventory = [];
  //--------------------------
  
  $scope.selectRoom = function(room){
      $scope.selectedRoom = room;
      c.server.get({action: 'getScheduledInventory', room: room.sys_id, task: c.data.current_task_id}).then(function(resp){
          $scope.currentInventory = resp.data.inventory;
      });
  }
  
  $scope.updateInventory = function(item, state, room){
      if($scope.modal){
          $scope.modal.close();
          
          $scope.currentInventory.push($scope.tempInvData.inventoryItem);
          $scope.modal = false;
      }
          
      c.server.get({action: 'updateInventory', id: item.sys_id, state: state , room: room }).then(function(resp){
          if(resp.data.wasUpdated){
              item.done = true;
              item.state = resp.data.newState;
              item.room = resp.data.room;
          }
      });
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/l0aVs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l0aVs.png" alt="What I want to update" /></a></p>