Links available on the Knowledge article should be displayed on a new widget on the portal

Sagar Rd
Tera Contributor

Hi All,

 

On the knowledge article I have reference links and I would like the reference links to be displayed on new widget. I would like to know the possibilities and how can this be achived.

 

Thankyou !!

1 REPLY 1

Ratnakar7
Mega Sage
Mega Sage

Hi @Sagar Rd ,
In the HTML template section of your widget, you can define how you want the links to be displayed. Here’s an example of how to do it:

<div>
  <h3>Reference Links</h3>
  <ul>
    <li ng-repeat="link in data.links">
      <a href="{{link.url}}" target="_blank">{{link.label}}</a>
    </li>
  </ul>
</div>

In the client script section of your widget, you need to fetch the reference links from the Knowledge Article and bind them to the widget's data. Here’s an example client script:

(function() {
  // Function to fetch reference links for a given knowledge article
  function fetchReferenceLinks(articleSysId) {
    // Initialize an empty array to store the links
    var links = [];

    // Define a GlideRecord to query the Knowledge Article table
    var gr = new GlideRecord('kb_knowledge');
    if (gr.get(articleSysId)) {
      // Assuming the reference links are stored in a field named 'u_reference_links' in JSON format
      // Example JSON: '[{"label": "Google", "url": "https://www.google.com"}, {"label": "ServiceNow", "url": "https://www.servicenow.com"}]'
      var referenceLinks = gr.getValue('u_reference_links');
      if (referenceLinks) {
        links = JSON.parse(referenceLinks);
      }
    }

    return links;
  }

  // Replace 'YOUR_KNOWLEDGE_ARTICLE_SYS_ID' with the actual Sys ID of the knowledge article
  var articleSysId = 'YOUR_KNOWLEDGE_ARTICLE_SYS_ID';

  // Fetch the reference links for the specified knowledge article
  $scope.data.links = fetchReferenceLinks(articleSysId);
})();

 

Thanks,

Ratnakar