Knowledge article

Yogita11_
Tera Contributor

Hello @all ,
I have the solution itself, but I'd appreciate some guidance to fully grasp its underlying mechanics and how it functions

Requirement - 
Basically the "Republish" button on kb article is not accesible for ownership group members it was only allowed to the knowledge admin and admin users. so our requirement was make it functional and visible to ownership group members as well. Hence I followed the below article. And provided souliton by "Sebastian" is worked for me I pasted the code in "KBCommon " script include.



https://www.servicenow.com/community/developer-forum/make-republish-button-visible-to-ownership-grou...

Yogita11__0-1750948454808.png

 

It got worked succefully, However my question is how this get linked with republish functionality, because if we check the UI Action of "republish" button. 

Yogita11__1-1750948718032.png

It has called "KBKnowledge" script include and inside that script include no any "republish" function is defined. And i found one more script include is called there "KBKnowledgeSNC" as shown in below screenshot.

Yogita11__3-1750948823616.png

So in that script include i found the function 

Yogita11__4-1750948932657.png

So my question is adding code in the "kbcommon" script include how does my issue resolved. Can someone help me to understand the connection and work behind this?

Yogita11__5-1750949002652.png

@Sebastian R_

 

 

 

2 ACCEPTED SOLUTIONS

Sebastian R_
Kilo Sage

Hi @Yogita11_ ,

this is working because of the extension-chain of the script include.

The extension is defined in line 2 of each script include "Object.extendsObject".

The chain looks the following: 

KBKnowledge -> KBKnowledgeSNC -> KBCommon -> KBCommonSNC

So going through the function chain it looks like this

Call "canRepublish" in KBKnowledge.
If "canRepublish" is not defined in KBKnowledge, use the definition from KBKnowledgeSNC.

KBKnowledgeSNC.canRepublish is not defined in KBKnowledge or KBKnowledgeSNC.
So we go deeper and check KBCommon and then KBCommonSNC.

As you haven overwritten the function in KBCommon, that´s why it is working

 

See also this course to learn more about the extension of script includes: https://developer.servicenow.com/dev.do#!/learn/courses/xanadu/app_store_learnv2_scripting_xanadu_sc...

 

View solution in original post

Yes correct. ServiceNow uses this concept in lot of scripts where you have the readonly SNC Script Include and the writeable version to overwrite functionality.

So ServiceNow will always call "KBKnowledge" so that you can overwrite the methods there.

View solution in original post

4 REPLIES 4

k_lutz
Tera Expert

My take on it is that in the original code only an admin can republish. In the custom code, which is a way to keep the existing logic as is and override it says that if the user is NOT an admin AND NOT a member/manager of the ownership group, deny access...so then it lets the ownership group have the access.

Sebastian R_
Kilo Sage

Hi @Yogita11_ ,

this is working because of the extension-chain of the script include.

The extension is defined in line 2 of each script include "Object.extendsObject".

The chain looks the following: 

KBKnowledge -> KBKnowledgeSNC -> KBCommon -> KBCommonSNC

So going through the function chain it looks like this

Call "canRepublish" in KBKnowledge.
If "canRepublish" is not defined in KBKnowledge, use the definition from KBKnowledgeSNC.

KBKnowledgeSNC.canRepublish is not defined in KBKnowledge or KBKnowledgeSNC.
So we go deeper and check KBCommon and then KBCommonSNC.

As you haven overwritten the function in KBCommon, that´s why it is working

 

See also this course to learn more about the extension of script includes: https://developer.servicenow.com/dev.do#!/learn/courses/xanadu/app_store_learnv2_scripting_xanadu_sc...

 

Thanks for the information, @Sebastian R_ 
Can you please help me to explore some things, as we can see in the below screenshot "

canPublish" function is defined in the  "KBKnowledgeSNC" script include which is read only. 

Yogita11__0-1751379978515.png
However, this get extended from the "KBKnowledge" script include (editable) so we can override the function in this script include right?

Yogita11__1-1751380115489.png

 

 

Yes correct. ServiceNow uses this concept in lot of scripts where you have the readonly SNC Script Include and the writeable version to overwrite functionality.

So ServiceNow will always call "KBKnowledge" so that you can overwrite the methods there.