Add new button to Knowledge view

wchaiwimol
Giga Contributor

Is it possible to add a new button for example Create HR Case to the knowledge view? The functionality will be similar to Create Incident. Thanks in advance for your help.

find_real_file.png

1 ACCEPTED SOLUTION

Doing some Developper console exploring, I found that the script that handles the createIncident button reside in the UI Script "KBViewArticle"



So you have: $j('#createIncident').click(this.incidentBtnHandler.bind(this));which handles the click of the button



Then the incidentBtnHandler function uses $j('#createIncidentLinkLocation').val(); to set the location



The #createIncidentLinkLocation refers to an hidden input field which is contained inside "kb_view_hidden_fields" UI Macro.



This createIncidentLinkLocation is based on the System property (sys_properties.list in SNOW navigator). This link looks a lot like what I suggested which is: "incident.do?sys_id=-1&sysparm_query=active=true^comments=(Created after Knowledge search: $[HTML:knowledgeRecord.short_description])&sysparm_stack=knowledge_home_launcher.do"



The important part in the link is the "$[HTML:knowledgeRecord.short_description]" part. Inside "kb_..." UI Macro you have access to knowledgeRecord jelly object which contains all your knowledge fields which you may want to use for your predefined values.You usually can use it in first phase ${knowledgeRecord.field} or in second phase $[knowledgeRecord.field]



So if you want to create your button the same way the create incident is done you would need to customize:



  • 3 UI Macro (kb_view_common_header_toolbar & kb_view_hidden_fields & kb_view_common in which the variable showCreateIncident is initialized based on the fact that the knowledge is in a popup or not)
  • 1 UI Script (KBViewArticle)
  • Insert a new system property


This has the pro of respecting the actual design but have the con of making a lot of modifications that can be harder to maintain than simply putting a onclick on your button.



Depending on your level of expertise in ServiceNow and with Jelly, I think I gave you enough info to do it yourself, but if you need more help, just ask.


View solution in original post

33 REPLIES 33

Hi,

 

Here is an example of the code for the email client button:

<button id="email_client_open" onclick="popupOpenEmailClient('email_client.do?sysparm_table=kb_knowledge&amp;sysparm_sys_id=${knowledgeRecord.sys_id}&amp;sysparm_target=kb_knowledge&amp;sys_target=kb_knowledge&amp;sys_uniqueValue=${knowledgeRecord.sys_id}')" src="images/icons/email.gifx" aria-label="Email" class="btn btn-icon icon-mail" title="" data-original-title="Email"></button>

 

You can add it to the UI Macro "kb_view_common_header_toolbar" To have it on the left of Flag article, you should add it just before this line:

 

<j:if test="${showFlagArticle &amp;&amp; show_kb_rating_options}"><!-- keep the extra spaces in ' Flag Article ' to get upper case words -->

 

The code passes info related to the knowledge record so you can go define an Email Client Template (sys_email_client_template) for the content of the email. An example would be: 

  • Table: kb_knowledge
  • Subject: ${number} - ${short_description}
  • Body HTML: <p><a title="${number} - ${short_description}" href="/kb_view.do?sysparm_article=${number}">${number} - ${short_description}</a></p>

 

I hope this helps you, let me know if you have any questions

 

Hi Laurent, Thanks for your reply , i was waiting for it . Laurent i tried adding the button code in " kb_view_common_header_toolbar" Macro file , But their is slightly change in the requirement I need the button at the below location on Knowledge Management V3 Homepage. and i am not being able to view the button after adding the button code in " kb_view_common_header_toolbar" file.

find_real_file.png

 

To my knowledge this page is not customizable. I don't see anyway to add a button to the knowledge base homepage.

Hi Laurent,

I have tried same code for showing "Mail" button on knowledge articles- Agent Workspace but I am not being able to view the button after adding the button code in " kb_view_common_header_toolbar" file.

Hi Harshada, the kb_view_common_header_toolbar does not seem to be used for knowledge articles in Agent Workspace.

If you are refering to the Agent Assist knowledge articles, the buttons seem to be defined in the "Contextual Search > Table Configurations" menu. In that table you have table configurations for Agent Assist where you can find "Search Action Configurations" which are defining the actions available.

However creating new Search Action doesn't seem to be supported.

What is your use case exactly? Why isn't the Attach button meeting your requirements?