- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 01:54 AM
Hi All,
I have added a Watch List widget on our portal with the guidance on this post.
However, what I am now trying to achieve is to only show certain users on the first field.
I would like to only users users with a specific email, so user.email contains 'abc.co.uk'.
Is this achievable through the widget code -
Server -
(function() {
var gr;
//if the user inputs data
if(input){
gr = new GlideRecord(input.table);
if(gr.get(input.sys_id)){
// if user has write access allow update of list
if(gr.watch_list.canWrite()){
gr.watch_list = input.watchList;
gr.update();
gs.addInfoMessage('Watch List Updated');
}
//if user does not have write access show error message
else{
gs.addErrorMessage("Update failed, you don't have the required access");
}
}
}
//if user isn't inputting data
else{
var table = $sp.getParameter('table');
var sys_id = $sp.getParameter('sys_id');
gr = new GlideRecord(table);
//Get the record data
if(gr.get(sys_id)){
data.table = table;
data.sys_id = sys_id;
data.canRead = gr.watch_list.canRead();
data.canWrite = gr.watch_list.canWrite();
//if user has read rights, display the watch list values
if(data.canRead){
var dV = gr.getDisplayValue('watch_list');
var sV = gr.getValue('watch_list');
//data.displayValue = dV == '' ? [] : dV;
//data.value = sV == null ? [] : sV;
data.displayValue = dV;
data.value = sV;
}
}
}
})();
/*distribution list function*/
(function() {
data.sys_id = $sp.getParameter('sys_id');
//if the user inputs data find the record
if (input) {
if(input.watch_list){
data.sys_id = input.sys_id;
var grTask = GlideRecord("task");
grTask.query("sys_id", data.sys_id);
grTask.query();
if (grTask.next()) {
var wList = grTask.watch_list;
var wEmail = input.watch_list;
// If there's already users listed
if(wList != "") {
wList = (wList + "," + wEmail);
}
//If the watch list is empty
else {
wList = wEmail;
}
//Update the record with new Watch List values
grTask.watch_list = wList;
data.displayValue = wEmail;
grTask.update();
}
}
}
})();
Client -
function($scope, spUtil, $http) {
var c = this;
$scope.watch_list = {
displayValue: c.data.displayValue,
value: c.data.value,
name: 'watch_list'
};
$scope.save = function(){
c.data.watchList = $scope.watch_list.value;
c.server.update().then(function() {
spUtil.recordWatch($scope, c.data.table, "sys_id=" + c.data.sys_id, function(name, data) {
if(name.name == 'record.updated' && data.operation == 'update'){
$scope.watch_list.value = data.record.watch_list.value;
$scope.watch_list.displayValue = data.record.watch_list.display_value;
$scope.$apply();
}
});
});
$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'watch_list'){}
});
};
}
Any help would be really appreciated.
Thanks!
Alex
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 03:12 AM
HI i have already shared the below code. Check the bold ones
<sn-record-picker field="watch_list" sn-disabled="!data.canWrite" table="'sys_user'" display-fields="'name'" display-field="'email'" search-fields="'name'" value-field="'sys_id'" default-query="'active=true^web_service_access_only=false^user_nameISNOTEMPTY^emailLIKEabc.co.uk'" page-size="10" multiple="true"></sn-record-picker>
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 01:57 AM
Hi you need to add query filter in HTML for this to work
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 02:08 AM
In your HTML i believe you have sn-record-picker you can add below query there
<sn-record-picker field="watch_list" sn-disabled="!data.canWrite" table="'sys_user'" display-fields="'name'" display-field="'email'" search-fields="'name'" value-field="'sys_id'" default-query="'active=true^web_service_access_only=false^user_nameISNOTEMPTY^emailLIKEabc.co.uk'" page-size="10" multiple="true"></sn-record-picker>
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 02:35 AM
Hi,
Thank you for getting back to me!
Here is the HTML -
<div class="panel panel-default" ng-if="data.canRead">
<div class="panel-heading">
<h4 class="panel-title pull-left" style="font-size: 14px;" ng-click="c.variable_toggle = !c.variable_toggle" aria-expanded="{{c.variable_toggle}}" aria-controls="variables-toggle">
<span style="font-size: 12px;" class="glyphicon" ng-class="c.variable_toggle ? 'glyphicon-chevron-down' : 'glyphicon-chevron-up'"></span> ${Watch List Actions}
</h4>
<div class="clearfix"></div>
</div>
<div ng-if="c.variable_toggle"class="panel-subheading" align="center" style="font-size: 12px;">${Click in the white box below to add users and select the "Update" button}</div>
<div ng-if="c.variable_toggle"class="panel-body">
<form ng-click="save()">
<div class="text-center text-italic text-muted">
<div>
<sn-record-picker field="watch_list" sn-disabled="!data.canWrite" table="'sys_user'" display-fields="'name'" display-field="'email'" search-fields="'name'" value-field="'sys_id'" default-query="'active=true^web_service_access_only=false^user_nameISNOTEMPTY^emailISNOTEMPTY'" page-size="10" multiple="true"></sn-record-picker> </div>
<div style="margin-top:15px; float: right;">
<button ng-if="data.canWrite" type="submit" class="btn btn-primary btn-sm">${Update}</button>
</div>
</div>
</form>
</div>
<div ng-if="c.variable_toggle" class="panel-body" style="font-size: 12px;">
<form>
${Distribution lists: type an email address in the box below and select the "Update" button}
<div class="textbox_space">
<input ng-disabled="!data.canWrite" ng-model="data.watch_list" id="watch_list_dist" class="form-control" type="email" maxlength="50" />
</div>
<input ng-if="data.canWrite" ng-click="save()" type="submit" id="submit" value="Update" class="btn btn-primary btn-sm" style="margin-top:10px; float: right;"/>
</form>
</div>
Can you please help with adding your line of code into this?
Thanks!
Alex

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 03:12 AM
HI i have already shared the below code. Check the bold ones
<sn-record-picker field="watch_list" sn-disabled="!data.canWrite" table="'sys_user'" display-fields="'name'" display-field="'email'" search-fields="'name'" value-field="'sys_id'" default-query="'active=true^web_service_access_only=false^user_nameISNOTEMPTY^emailLIKEabc.co.uk'" page-size="10" multiple="true"></sn-record-picker>
Harish