---
original_url: "https://jace.pro/blog/service-portal-modify-watch-list/"
format: markdown
ai_optimized: true
---

Service Portal - Modify Watch List# Service Portal - Modify Watch List

October 4, 2017 [servicenow ](/tags/servicenow/)[service-portal](/tags/service-portal/)

  Enable AI AnimationI created a widget and wanted to share that code. Should work on any
instance unless you have a business rule blocking the update.

## [Client Script](#client-script)

`function($scope, spUtil) {
  var c = this;
  $scope.watch_list = {
    displayValue: c.data.watch_list.displayValue,
    value: c.data.watch_list.value,
    name: 'watch_list'
  };
  $scope.updateRecord = function(){
    c.data.watch_list = $scope.watch_list;
    c.server.update()
  };
}`## [Server Script](#server-script)

```
`(function() {
  if(input && input.sys_id && input.table && input.watch_list){
    var ticket = new GlideRecord(input.table);
    if(ticket.get(input.sys_id)){
      ticket.setValue('watch_list', input.watch_list.value);
      ticket.update();
    }
  } else {
    if($sp.getParameter('table') && $sp.getParameter('sys_id')){
      var table = $sp.getParameter('table')
      var sys_id = $sp.getParameter('sys_id')
      var gr = new GlideRecord(table);
      if(gr.get(sys_id)){
        data.canRead = gr.watch_list.canRead();
        data.canWrite = gr.watch_list.canWrite();
        if(data.canRead){
          data.sys_id = sys_id;
          data.table = table;
          data.watch_list = {
            displayValue : gr.getDisplayValue('watch_list') || '',
            value : gr.getValue('watch_list') || ''
          };
        }
      }
    } else {
      //missing url params
    }
  }
})();`
```

## [HTML](#html)

```
`<div ng-if="data.canRead" class="panel panel-primary b">
  <div class="panel-heading">
    <h4 class="panel-title pull-left">
      ${Watch list}
    </h4>
    <div class="clearfix"></div>
  </div>
  <div class="panel-body">
    <div class="text-center text-italic text-muted" id="watch_list_div">
      <sn-record-picker 
        ng-blur="updateRecord()"
        field="watch_list"
        sn-disabled="!data.canWrite"
        table="'sys_user'"
        display-field="'name'"
        search-fields="'name'"
        value-field="'sys_id'"
        default-query="'active=true^name!=NULL'"
        multiple="true">
      </sn-record-picker>
      <p></p>
      <button 
        type="button"
        ng-click="updateRecord()"
        ng-if="data.canWrite"
        class="btn btn-default ng-scope">
        Update Watch List
      </button>
    </div>
  </div>
</div>`
```

---
[View this page on GitHub](https://github.com/jacebenson/jace.pro/tree/main/./src/posts/2017/2017-10-03-sp-modify-watch-list.md).

[Service Portal - Modify Watch List](https://jace.pro/blog/service-portal-modify-watch-list/) [Jace Benson](https://jace.pro) ![Jace Benson](https://jace.pro/icon-512x512.png)

---

*This content is from Jace Benson's ServiceNow and tech blog at jace.pro*
*Original post: https://jace.pro/blog/service-portal-modify-watch-list/*
