0

Before doing any modifications I suggest making a copy of the following UI Macros (for example by using Insert and Stay from the context menu on the form). We will be modifying these later.

  • kb_view_common_header_banner_image
    • /nav_to.do?uri=sys_ui_macro.do?sys_id=b74cff91c30031000096dfdc64d3ae65
  • kb_view_common_footer_metadata_fields (only if you want to remove the link from the footer of the kb_view)
    • /nav_to.do?uri=sys_ui_macro.do?sys_id=3783deb1d70031004792a1737e610391

You should deactivate the original ones so the system uses your new macros.

Now you can go ahead and create a new UI Macro, I named it kb_view_permalink, and copied the following piece of code from kb_view_common_footer_metadata_fields with some modifications:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
 <j2:if test="$[sysparm_media != 'print']">
 $[SP]<a href="#" id="permalink" aria-label="${gs.getMessage('Copy Permalink')}">${gs.getMessage('Copy Permalink')}</a>
 <script language="javascript">
  $j('#permalink').click(
   function(){
    //generate direct url to this article, by getting the domain and adding sysparm_article=NUMBER_OF_ARTICLE
    copyToClipboard(window.location.origin + '${permalink}');
    return false;
   }
  );
 </script>
 </j2:if>
</j:jelly>

You can now add this macro into your version of kb_view_common_header_banner_image where you want the link to appear. I have added it right next to the KB number and Latest version link, in my instance this is right after line 47:

</j:if>
  <j:if test="${state!=''}">$[HTML:state]</j:if>
  <!-- Added by Lucas Vieites 20200320 -->
  <g:inline template="kb_view_permalink" />    <===== This is the line you need to add
  <!-- END of Lucas Vieites 20200320 -->
</div>

Adding "Copy Permalink" to the top of your Knowledge Base Article view (kb_view)
Working Code Asked question June 17, 2024