How can we hide cart icon on header in service portals depending on company in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 02:24 AM
We have cart icon on header menu of Service Portal, this can be hide if we set below value to false but I want it to hide only when logged in user is from company A. for logged in user from other company except A it should be visible.
{
"enable_cart": {
"displayValue": "true",
"value": false
},
"enable_wishlist": {
"displayValue": "true",
"value": false
}
}
Please advice how can we achieve this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 02:35 AM
To hide the cart icon on the header in Service Portals depending on the company in ServiceNow, you can follow these steps:
1. Navigate to the Service Portal Configuration.
2. Open the page where you want to hide the cart icon.
3. Find the widget that is responsible for displaying the cart icon. It's usually in the header widget.
4. Open the widget instance and navigate to the server script or client controller script.
5. In the script, you can add a condition to check the company of the logged-in user. You can use the GlideUser API to get the company of the current user. Here is a sample code:
javascript
var user = gs.getUser();
var company = user.getCompanyID();
6. Based on the company, you can decide whether to display the cart icon or not. Here is a sample code:
javascript
if (company == 'your_company_sys_id') {
data.showCartIcon = false;
} else {
data.showCartIcon = true;
}
7. Save the changes and refresh the portal to see the changes.
Please note that this is a high-level overview and the actual implementation might vary based on your ServiceNow version and configuration. Always test your changes in a non-production instance before applying them to production.
nowKB.com
For a good and optimistic result, and solving ServiceNow-related issues please visit this website.https://nowkb.com/home
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 05:13 AM
Hi Ahana,
I tried using above solution but its not working. I have pasted the code below. If you can take a look and let us know where to update it might help me. Thank you.
Server side code:
$scope.collapse = function() {
$rootScope.$emit('sp-navbar-collapse');
}
$scope.loadingIndicator = $rootScope.loadingIndicator;
$scope.cartItemCount = 0;
$scope.wishlistItemCount = 0;
$scope.itemAddedTooltipOpen = false;
$scope.toursTooltipEnabled = true;
$scope.accessibilityEnabled = spAriaUtil.g_accessibility === "true";
$scope.$on("$sp.service_catalog.cart.count", function($evt, count) {
$scope.cartItemCount = count;
});
$scope.$on("$sp.service_catalog.wishlist.count", function($evt, count) {
$scope.wishlistItemCount = count;
});
var cancelTooltipPromise;
$scope.$on("$sp.service_catalog.cart.add_item", function() {
$timeout.cancel(cancelTooltipPromise);
$scope.itemAddedTooltipOpen = true;
cancelTooltipPromise = $timeout(function() {
$scope.itemAddedTooltipOpen = false;
}, 3000);
});
$scope.$on('sp_loading_indicator', function(e, value) {
$scope.loadingIndicator = value;
});
$scope.toggleCart = function() {
$timeout.cancel(cancelTooltipPromise);
$scope.itemAddedTooltipOpen = false;
$timeout(function() {
$("#cart-dropdown").dropdown("toggle");
});
};
$scope.toggleTours = function() {
var action = $scope.toursTooltipEnabled ? 'disable' : 'enable';
$scope.toursTooltipEnabled = $scope.toursTooltipEnabled ? false : true;
$('[data-toggle-second="tooltip"]').tooltip(action);
if(action == 'disable')
$('[data-toggle-second="tooltip"]').tooltip('hide');
}
$scope.onToursItemBlur = function() {
$('[data-toggle-second="tooltip"]').tooltip('enable');
$scope.toursTooltipEnabled = true;
}
// PRB1108244: visibleItems array is used to improve keyboard nav
// in menu, refresh it as needed
$scope.$watch('data.menu.items', function() {
$scope.visibleItems = [];
if ($scope.data.menu.items) {
for (var i in $scope.data.menu.items) {
var item = $scope.data.menu.items[i];
if (item.items || (item.scriptedItems && item.scriptedItems.count != 0))
$scope.visibleItems.push(item);
}
}
}, true);
$scope.$on('sp-menu-update-tours', function(event, tours) {
$scope.data.showTours = $scope.data.showTours && !spUtil.isMobile();
if ($scope.data.showTours === false) {
$scope.data.guidedTours = null;
return;
}
var guidedToursLabel = 'Guided Tours';
$scope.data.guidedTours = {
label: guidedToursLabel,
collection: []
};
$scope.tooltipTours = tours.length === 1 ? i18n.getMessage('This page currently has 1 tour') : i18n.getMessage('This page currently has {0} tours').withValues([tours.length])
if (tours.length > 0) {
$scope.data.guidedTours.collection = tours.map(function(t) {
return {
title: t.name,
id: t.id,
clicked: function() {
spGtd.launch(t.id);
}
};
});
}
});
// Get list of record watchers
var record_watchers = [];
if ($scope.data.menu.items) {
for(var i in $scope.data.menu.items) {
var item = $scope.data.menu.items[i];
if (item.type == 'scripted') {
if (item.scriptedItems.record_watchers)
record_watchers = record_watchers.concat(item.scriptedItems.record_watchers);
}
if (item.type == 'filtered') {
record_watchers.push({'table':item.table,'filter':item.filter});
}
}
}
// Init record watchers
for (var y in record_watchers){
var watcher = record_watchers[y];
spUtil.recordWatch($scope, watcher.table, watcher.filter);
}
$rootScope.$broadcast('sp-header-loaded');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 03:20 AM
Are you using domain separation?
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 04:51 AM
no not domain separation