Add favorite option on articles on a portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 04:59 AM - edited 07-24-2023 05:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 05:39 AM
Hi @Naveen Kokkirap ,
Please check this Product Doc : https://docs.servicenow.com/en-US/bundle/utah-employee-service-management/page/product/employee-cent...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 05:43 AM - edited 07-24-2023 05:44 AM
i already know this, it was already enabled and we can configure for employee center, but i need to know how to do for other portals
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 06:05 AM
Hi @Naveen Kokkirap ,
Hope you are doing great.
To add a "favorite" option to articles on a custom portal:
Create a new field in the existing Article table to track the favorite status. Let's name it "favorite."
Modify the custom portal's article page to display a heart icon or any other symbol to represent the "favorite" option.
<!-- Add this code to the article page template -->
<!-- Replace the placeholder icon with a heart icon or any desired symbol -->
<div class="article-actions">
<span class="favorite-icon">♡</span>
</div>
Implement a client-side script to handle the user interaction with the "favorite" option. This script should toggle the "favorite" status when the user clicks on the heart icon.
// Add this code to a client script
document.querySelector('.favorite-icon').addEventListener('click', function() {
var articleId = /* Get the article ID from the current page */;
var isFavorite = /* Get the current "favorite" status for the article */;
// Toggle the "favorite" status
isFavorite = !isFavorite;
// Update the heart icon based on the new status
this.textContent = isFavorite ? '♥' : '♡';
// Send the updated status to the server
/* Code to call the server-side script or AJAX request to update the "favorite" field */
});
Next, develop a server-side script or business rule that updates the "favorite" field in the Article table whenever a user marks an article as a favorite or removes it from favorites.
// Add this code to a business rule or a server-side script
// This script should be triggered when the "favorite" status is updated on the client-side
(function() {
var articleId = /* Get the article ID from the client-side request */;
var isFavorite = /* Get the updated "favorite" status from the client-side request */;
var articleGR = new GlideRecord('article');
if (articleGR.get(articleId)) {
articleGR.favorite = isFavorite;
articleGR.update();
}
})();
To ensure security and control, configure ACLs (Access Control Lists) to restrict access to the "favorite" option and ensure that only authorized users can mark articles as favorites.
Additionally, you may want to create a dedicated list view or filter to display all favorited articles for each user on the custom portal.
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 02:03 AM
Hello Riya
Your quick response is appreciated!
But here the scenario is, making favs will be done by individual. It should show their favorites only when they try to see.
Hope you have understood