- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 02:16 PM
We need to dynamically filter the tiles that show on the All On-Call Schedules tab on $oc_groups. We have tried both ACLs against cmn_rota and updating sn_on_call_now.app UI Script, but neither solution has any impact on the results for All On-Call Schedules. In case it helps, these are the script changes that were made for the sn_on_call_now.app (adding in the service for AllFilter). The filter isn't important, I'm just testing a possible solution in a personal dev before we implement the real filter we need to apply.
angular.module("sn.on_call.now.groups").service("GroupFilterService", ["$window", "PinnedService", "TextSearchService", "ManagedBelongService","AllFilter", function($window, PinnedService, TextSearchService, ManagedBelongService,AllFilter) {
var groupFilterService = this;
var _allGroups = [];
function getAllGroups(groups) {
if (_allGroups.length !== groups.length)
_allGroups = groups.slice();
return _allGroups;
}
groupFilterService.getFilteredGroups = function(groups, filterBy, textSearch, textSearchType, pinnedGroups) {
var filteredGroups = [];
//filteredGroups = getAllGroups(groups);
if (filterBy === "all")
filteredGroups = AllFilter.getFilteredGroups(groups, $window.NOW.user_id || "");
else if (filterBy === "manage_belong")
filteredGroups = ManagedBelongService.getFilteredGroups(groups, $window.NOW.user_id || "");
else if (filterBy === "pinned")
filteredGroups = PinnedService.getFilteredGroups(groups, pinnedGroups);
else
filteredGroups = [];
return TextSearchService.getFilteredGroups(filteredGroups, textSearch, textSearchType);
};
}]);
///ADDING:
angular.module("sn.on_call.now.groups").service("AllFilter",[function(){
var allFilter = this;
var _all = [];
var _groups = [];
allFilter.getFilteredGroups = function(groups, activeUserID){
if(!groups || groups.length < 1 || !activeUserID){
_all = [];
_groups = [];
}
else if(_groups.length !== groups.length){
_groups = groups.concat(_groups);
var allowedGroups = [];
groups.filter(function(group){
var types = group.type;
if(types.indexOf('74af88c6c611227d0066386e74dc853d') != -1){
allowedGroups.push(group);
}
});
_all = allowedGroups;
}
return _all;
};
}]);
//...many lines edited out
angular.module("sn.on_call.now.groups").controller("GroupOnCallController", ["$scope", "GroupService", "GroupFilterService", "ManagedBelongService", "PinnedService", "TextSearchService", "$window", "$location", "userPreferences", "getTemplateUrl", "i18n", "$timeout", "snConnectService", "HighlightService", "$injector", "$sce", "$interval", "KeyCode", "AllFilter" , function($scope, GroupService, GroupFilterService, ManagedBelongService, PinnedService, TextSearchService, $window, $location, userPreferences, getTemplateUrl, i18n, $timeout, snConnectService, HighlightService, $injector, $sce, $interval, KeyCode, AllFilter) {
//...many lines edited out
function _splashScreenVisibility() {
groupOnCallCtrl.isWizardBtnPrimary = groupOnCallCtrl.pinnedGroups.length === 0;
groupOnCallCtrl.showPinnedSplashMsg = (groupOnCallCtrl.groupFilter === "pinned" && PinnedService.getFilteredGroups(groupOnCallCtrl.groups, groupOnCallCtrl.pinnedGroups).length === 0);
groupOnCallCtrl.showManageBelongSplashMsg = (groupOnCallCtrl.groupFilter === "manage_belong" && ManagedBelongService.getFilteredGroups(groupOnCallCtrl.groups, $window.NOW.user_id).length === 0);
//groupOnCallCtrl.showAllSplashMsg = (groupOnCallCtrl.groupFilter === "all" && groupOnCallCtrl.groups.length === 0);
groupOnCallCtrl.showAllSplashMsg = (groupOnCallCtrl.groupFilter === "all" && AllFilter.getFilteredGroups(groupOnCallCtrl.group, $window.NOW.user_id).length === 0);
groupOnCallCtrl.textSearchReadOnly = groupOnCallCtrl.showPinnedSplashMsg || groupOnCallCtrl.showManageBelongSplashMsg || groupOnCallCtrl.showAllSplashMsg;
if (groupOnCallCtrl.textSearchReadOnly)
groupOnCallCtrl.textSearch = "";
groupOnCallCtrl.showOnCallRotas = (groupOnCallCtrl.groups.length > 0 && !groupOnCallCtrl.showPinnedSplashMsg && !groupOnCallCtrl.showManageBelongSplashMsg && !groupOnCallCtrl.showAllSplashMsg);
// Strip out extraneous tabindex
$timeout(function() {
angular.element(".sub-avatar").each(function() { angular.element(this).removeAttr("tabindex"); });
}, 0);
}
//...many lines edited out
}]);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2019 07:52 AM
After putting the before query business rule in our company dev instance, we found that it is being applied both in the $oc_groups and $oc_workbench and $oc pages in all areas where they can change the on-call schedule that they are looking at.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2019 01:23 PM
I've been able to get a filter to work in part with the following update to the new AllFilterService. However, I have two remaining issues:
- On initial load, if the user's default tab is the "All", it returns no results. They have to click to pinned or my and back to all to view the results. Any tips on getting the filter to run on load correctly?
- Once you click into a schedule, you're taken to the $oc_workbench, there is a drop down near the top of the page to select another group. I need to apply a filter here as well. However, I don't see us having access to this UI page. How can I limit the options on the workbench drop down?
angular.module("sn.on_call.now.groups").service("AllFilterService",[function(){
var allFilterService = this;
var _all = [];
var _groups = [];
allFilterService.getFilteredGroups = function(groups, activeUserID){
if(!groups || groups.length < 1 || !activeUserID){
_all = [];
_groups = [];
}
else if(_groups.length !== groups.length){
_groups = groups.concat(_groups);
var allowedGroups = [];
groups.filter(function(group){
var requestBody = "";
var client = new XMLHttpRequest();
client.open("get","https://dev82038.service-now.com/api/now/table/sys_user_group?sysparm_query=sys_id%3D"+group.sys_id+"&sysparm_fields=type&sysparm_limit=1");
client.setRequestHeader('Accept','application/json');
client.setRequestHeader('Content-Type','application/json');
client.setRequestHeader('Authorization', 'Basic '+btoa('admin'+':'+'Th0m4s195!'));
client.onreadystatechange = function() {
if(this.readyState == this.DONE) {
//document.getElementById("response").innerHTML=this.status + this.response;
var grType = this.response;
if(grType.indexOf('74af88c6c611227d0066386e74dc853d') > -1){
allowedGroups.push(group);
}
}
};
client.send(requestBody);
});
_all = allowedGroups;
}
return _all;
};
}]);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2019 02:59 PM
I changed methods completely to solve the filtering issue for $oc_groups. Adding a before query business rule against cmn_rota seems to fix that UI page and will only show my users what I want them to see (there are five on call schedules, this user only sees two from "all on-call schedules").
However, this fix does not work on the $oc_workbench "groups" drop down:
Has anyone had success filtering this drop down menu?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2019 07:52 AM
After putting the before query business rule in our company dev instance, we found that it is being applied both in the $oc_groups and $oc_workbench and $oc pages in all areas where they can change the on-call schedule that they are looking at.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2020 10:21 AM
Hi Kristen,
I have questions about On-Call Scheduling and you seem like a person who might have the answer.
I've a bunch of data to import for shifts and schedules, so I'm trying using import sets.
Questions :
1. Is it possible to use import set for this module, as so many things are inter-related here, and every entry has schedule and schedule entries.
2. I cannot find this fields "Allow Shift Schedule overlap" "Escalation rule on Shift overlap" anywhere in tables, which are present on create on-call schedule wizard.
Please respond at earliest.
Regards,
Laukik.