How to get a watch list in widget in Service Portal ?

Nithin12
Tera Expert

Hi Team,

How to get watch list for a particular ticket opened in service portal.

How to create a widget for this?

Any suggestions or ideas will help me a lot.

Thanks.

PlatformDeveloper Community

1 ACCEPTED SOLUTION

Hi Nithin,



Here is a quick widget I made, however it does not have any save functionality so you would have to add that. Also the sn-record-picker does not allow to add an email address as the usual watch list field does. If your goal is only to display a read of what was set on creation than this would do the job by simply setting sn-disabled="true".



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">


              <sn-record-picker field="watch_list" sn-disabled="!data.canWrite" table="'sys_user'" display-field="'name'" search-fields="'name'" value-field="'sys_id'" default-query="'active=true'" multiple="true"></sn-record-picker>


          </div>


  </div>


</div>



Client script:


function($scope, spUtil) {


      var c = this;


     


      $scope.watch_list = {  


              displayValue: c.data.displayValue,  


              value: c.data.value,


              name: 'watch_list'  


  };


}



Server script:


(function() {


     


      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.displayValue = gr.getDisplayValue('watch_list');


                      data.value = gr.getValue('watch_list');


              }


      }


})();



I know this is incomplete but I hope it helps.


View solution in original post

65 REPLIES 65

Hi Laurent

I used your above code but it seems I can't select any item (user) from the list, while I choose someone nothing happened.
What am I missing? can you help?
I didn't changed yet any code of yours.


find_real_file.png

Hi avivs,

Sorry for the confusion, this thread has grown and has becomed hard to follow.

Try replacing this section of the server side script

var dV = gr.getDisplayValue('watch_list');
var sV = gr.getValue('watch_list');
data.displayValue = dV == '' ? [] : dV;
data.value = sV == null ? [] : sV;

With this:

data.displayValue = gr.getDisplayValue('watch_list') || '';
data.value = gr.getValue('watch_list') || '';

Also testing the widget, I saw a different bug when trying to empty the watch list nothing was saved. So replace:

if(input && typeof input.watchList){

With:

if(input && typeof input.watchList != 'undefined'){

 

If these adjustements don't work don't hesitate to reply. Try to include any javascript error appearing in the browser console if it is the case.

Since this thread is already hard to follow, I will update the code that you used in my previous reply.

It's working now! Thanks a lot Laurent 🙂


BR,
Aviv

Thanks for this!

I've worked this in with some other "ticket management" features I've built.

One question, do you know how I could add a second piece of information? Like some of our users have the same first and last name. We've used added their title as an additional field of information from their sys_user profile on things like the "Caller" field etc.. Any advice on how to sort of merge the name and then have their title show as well?

(Edit: got sort of close...but now when I refresh it's showing their sys_id, instead of just the name. bah!)

<sn-record-picker field="watch_list" sn-disabled="!data.canWrite" table="'sys_user'" display-fields="'name';'title'" search-fields="'name'" value-field="'sys_id'" default-query="'active=true^web_service_access_only=false^user_nameISNOTEMPTY'" multiple="true"></sn-record-picker>

It seems as soon as there's two pieces of information what gets displayed back in the box is their sys_id, but when searching it shows their name and then their title underneath their name sort of "subscript" like.

Almost got it!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Laurent,

Can I use this in 'Catalog Checkout Custom' widget? I've added a watchlist field in the popup widget but I don't know where to insert the code since it has a custom checkout button.

Thanks