Is it possible to restrict the number of favorites to "30" in My Favorites page in Employee center
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2024 03:43 AM
Is it possible to restrict the number of favorites to "30" in My Favorites page in Employee center. If user try to add favorites more than "30", an error message should be displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2024 04:10 AM - edited ‎12-18-2024 09:09 AM
Hi @chandanap ,
Yes, it is possible to limit the number of favorites displayed on the "My Favorites" page in the Employee Center to 30.
Here’s how you can do it:
1. Write a business rule on the Portal Favorite table.
2. Table: sp_favorite
3. When to run: before insert
4. In advance section add the below script and save it.
(function executeRule(current, previous /*null when async*/) {
// Initialize a GlideRecord object for the 'sp_favorite' table
var favoriteRecord = new GlideRecord("sp_favorite");
// Query to find all favorite records for the current user
favoriteRecord.addQuery("user", gs.getUserID());
favoriteRecord.query();
// Check if the user has exceeded the maximum allowed favorites
if (favoriteRecord.getRowCount() > 30) {
// Display an error message to the user
gs.addErrorMessage("You have reached the maximum limit of 30 favorites. Please remove some items to add new favorites.");
// Abort the transaction
current.setAbortAction(true);
}
})(current, previous);
5. In the employee center mark an item as a favorite. If the count is greater than 30 error message is shown as previewed in the below screenshot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2024 04:40 AM
Why would you want to do this?