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 Laurent,

i need to add this helped fuctionality in kb page as create incident.

i have edited kb_view_common_header_toolbar and made the button visibilty but fuctionality is not working.

find_real_file.png

 

can you please help me  on where to add the onclick functionality for this helped.

 

Thanks

 

Could you please show us how this is done? When I am viewing a knowledge article, I would like to be able to have a button that will allow me to create a case from the Knowledge Article. The case should have the same Category/Title as the knowledge article from which the case was created. How can this be done step by step? 

Hi Laurent Chicoi1,

I have a below requirement

I can see an Add to Favorite UI action between Subscribe and Flag Article UI actions.

Dhanakoddi2_1-1684920924835.png

 

 

I can select the Add to Favorite UI action and the article is added as a favorite in the sp_favorite table and viewable in the Knowledge > Articles > My Favorites menu module. 

I can see Remove as Favorite when Add to Favorite has been previously selected.  

I can select Remove as Favorite and have the article removed from the sp_favorite table and no longer viewable in the Knowledge > Articles > My Favorites menu.

I can expect that my favorited articles listed in Knowledge > Articles > My Favorites menu option will always be the latest version of the KB article.

 

I am very new to this jelly script. Could you please suggest me how I can achieve this?

Thanks in Advance!

Hi Laurent,



Thanks for the post. I tried adding Print button to the KB article via your method of modifying UI macro. Though I see the Print button on KB Article and also it opens up Printer friendly view of the KB article but it doesn't open the Print window and seems it's not executing window.print() piece of the code. Can you please suggest on it ?    



Thanks


Bhupinder


Hi Bhupinder,



Is the Print button still available in your printer friendly view?



Also could you make sure that the opened window contains "&sysparm_media=print" inside the URL?



If the print button is not displayed, then could you make sure the <script> tag is being executed by adding this line to the first line of the script block:


alert("this script is running");



So you can see if the script is called at call