Add favorite option on articles on a portal

Naveen Kokkirap
Tera Contributor

Add favorite option on articles on a portal, i have done some analysis and i got that by default it was there in Employee center and but im working on one custom portal so i need same functionality for articles in a portal

 

 

5 REPLIES 5

Community Alums
Not applicable

Naveen Kokkirap
Tera Contributor

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

Riya Verma
Kilo Sage
Kilo Sage

Hi @Naveen Kokkirap ,

 

Hope you are doing great.

 

To add a "favorite" option to articles on a custom portal:

  1. Create a new field in the existing Article table to track the favorite status. Let's name it "favorite."

  2. 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.

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

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