Implement a "Create Knowledge Article" Button

Once a case or an incident is solved, your customer support agents may want to create a knowledge article for future reference. To help them accomplish this task, you can implement a “Create Knowledge Article” button thanks to ServiceNow’s UI actions. The button appears on the case or incident form and acts as a shortcut to open a knowledge article creation form.

Alternatively, you can add this button to the Insight Panel that appears in case or incident forms.

To implement a Create Knowledge Article button in your case and/or incident forms, follow the instructions in the ServiceNow documentation.

Configure your UI action as follows:

  • Check the Client box.

  • Check the Form button, Form content menu, and/or Form link boxes to determine where the button will appear.

  • In the Onclick box, enter redirectToCreateKB().

  • In the Script box, enter the JavaScript code to execute when a user clicks the button. We recommend that you adapt the sample below to your needs. The g_form.getValue function allows you to reuse the desired incident/case form values in the knowledge article. With the logCustomEvent function, Coveo logs the knowledge article creation, which then contributes to make the case or incident appear higher in search results, as it is considered more relevant.

    function redirectToCreateKB() {
      var title = g_form.getValue("short_description");
      var caseId = g_form.getUniqueValue();
      var coveoRoot = document.querySelector("#search");
      var event = { name: 'createKbFromCase', type: 'case' };
      Coveo.logCustomEvent(coveoRoot, event, { caseId: caseId });
      var query = "short_description=" + title + "^source=" + caseId;
      window.open("/kb_knowledge.do?sys_id=-1&sysparm_query=" + encodeURIComponent(query), "_blank");
    }
    

Adding the Button to an Insight Panel

On the Search Pages page, open the search interface corresponding to the Insight Panel in your case or incident form.

In the Interface Editor, switch to the code view, and then add the following code to your page:

<div>
  <a id="CreateKbLink" href="/kb_knowledge.do?sys_id=-1" target="_blank">
    <button type="button">Create Knowledge Article</button>
  </a>
</div>

Optionally, you can add a script underneath to reuse the desired incident/case form values in the knowledge article. We recommend that you adapt the following sample to your needs.

<script>
  var link = document.getElementById('CreateKbLink');
  var caseId = g_form.getUniqueValue();
  var coveoRoot = document.querySelector("#search");
  var event = { name: 'createKbFromCase', type: 'case' }; Coveo.logCustomEvent(coveoRoot, event, { caseId: caseId });
  var query = `short_description=${g_form.getValue('short_description')}^source=${caseId}`; link.setAttribute('href', '/kb_knowledge.do?sys_id=-1&sysparm_query=' + encodeURIComponent(query));
</script>
What's Next for Me?