Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Contact not able to edit Watchlist on Service Portal

Hardik Panchal
Mega Guru

Hello all

I have created a custom Watchlist widget to add only Servicenow users to a Case Watchlist.

As a system admin I can add all the users from Servicenow to any Case which works fine(See Screenshot).

find_real_file.png

But When I impersonate a contact and in their case when I try to add a User to the watchlist , I see no user in the watchlist.(See screenshot). What I want is that a Contact should be able to only add his/her colleague from the same Account/Company and not any other user.

find_real_file.png

HTML:

<div ng-if="data.canRead" class="panel panel-primary b">
<div class="panel-heading">
<h4 class="panel-title pull-left">
<a data-toggle="collapse" href="#collapse1">${Watch list}</a>
</h4>
<div class="clearfix"></div>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">
<span class="lock"></span>
<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
</button>

Client Script:

function($scope, spUtil) {
$scope.sVisible =false;
$scope.dVisible =false;

var c = this;
$scope.watch_list = {
displayValue: c.data.watch_list.displayValue,
value: c.data.watch_list.value,
name: 'watch_list'
};
$scope.updateRecord = function(){
if($scope.watch_list.value == ""){
$scope.sVisible =false;
c.server.update()
return;
}else{
$scope.sVisible =true;
c.data.watch_list = $scope.watch_list;
c.server.update()
}

};
}

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
}
}
})();

Please help.

Thanks in advance.

7 REPLIES 7

Rajababu
Giga Guru

Hi ,

Do you have code for auto update ,because when watchlist was added but ,It wont trigger email to watcher .

But when i add to other field standard access ,it didn't updated on the record ?

p_espinar
Kilo Guru

Hardik,

you have to add an ACL read to the contacts table in order to allow your end users to see their colleagues.

Something like this:

find_real_file.png

Un saludo,
Pablo Espinar
Consultant at Econocom Spain

Please mark this response correct if I've answered your question. Thanks! 

vibha13
Kilo Contributor

How have you achieved this?