How to create custom UI actions on the KB article view page?

SK07
Tera Contributor

Hi Community,

 

I'm currently working on customizing the Knowledge Base in ServiceNow and had a question regarding UI Actions on the Knowledge Article view page.

 

Requirement:
I want to create a custom UI Action (button) that appears on the Knowledge Article view page (kb_view / Knowledge Portal view), and perform a specific action when clicked.

 

Any guidance, examples, or documentation links would be greatly appreciated.

 

Thanks in advance!

1 REPLY 1

Naveen20
ServiceNow Employee

Customize the UI Macro

  1. Navigate to System UI → UI Pages → kb_view. Open the Jelly source and look for <g:call> or <g:include> tags — these reference the UI Macros that render the button bar (commonly something like kb_view_article_actions).
  2. Clone that UI Macro (never edit OOB directly). In your cloned macro, add your button:
 
 
xml
<j:if test="${gs.hasRole('your_required_role')}">
  <button class="btn btn-default" onclick="yourCustomAction('${jvar_article_sys_id}')">
    Your Button
  </button>
</j:if>
  1. Update the kb_view UI Page to reference your cloned macro instead of the original.
  2. Add your server-side logic via a Script Include, and call it from the button using GlideAjax:
 
 
javascript
function yourCustomAction(sysId) {
  var ga = new GlideAjax('YourScriptInclude');
  ga.addParam('sysparm_name', 'yourMethod');
  ga.addParam('sysparm_article_id', sysId);
  ga.getXMLAnswer(function(response) {
    alert('Done: ' + response);
  });
}