We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Regarding Adding Info Message in the KB when it is opened in the Service Portal but not Native UI.

imranshaik0
Tera Contributor

Hi Community!!

I am having a requirement.

There is a field in knowledge form with internal users and it is checkbox type. Whenever it is checked, if the user try to preview article using the UI action or in Service Portal but not in native UI (Platform), It should add a note in the Body Template "it is for Internal users only". And if it is unchecked, it should add a note in the Body Template  "It is for external users only." Suggest me the best way I can try and work out in my PDI?


Or if it can't be done, I want to display a Info message or an alert when the user tries to open the KBA. How it can be done? Suggest me the best and simple way to complete this requirement.

Note: I am new bee to Service Portal and I am expecting End to End guidance. 

3 REPLIES 3

KrishnaMohan
Giga Sage

Hi @imranshaik0 

 

The Service Portal uses Widgets to display articles (usually the Knowledge Article Contentwidget). Standard Client Scripts often don't run here, so we have two simple options

 

Option 1:  The most reliable way for Knowledge is a Display Business Rule.

  1. Navigate to Business Rules -> New.

  2. Table: Knowledge [kb_knowledge]

  3. Advanced: Checked.

  4. When: display

var msg = current.u_internal_users == true ? "It is for Internal users only" : "It is for external users only";
 // gs.addInfoMessage works in both Native UI and Service Portal
 gs.addInfoMessage(msg);

 This will show a blue info bar at the top of the article in the Portal.

 

Option 2: Injecting Text into the Body

  If you strictly want the text inside the body template, you would need to modify the Knowledge Article Content widget.
      

  • Go to Service Portal -> Widgets.

  • Find the widget Knowledge Article Content  (ID: kb-article-content)  or use this  (/sp_widget.do?sys_id=a47ea1cb0b9432004ce28ffe15673a5b&sysparm_record_target=sp_widget&sysparm_record_row=1&sysparm_record_rows=2&sysparm_record_list=idSTARTSWITHkb-article%5EORDERBYDESCsys_updated_on).

  • Clone the Widget (ServiceNow doesn't let you edit "Out of Box" widgets directly).

  • In the HTML Template, look for the line that renders the article body (usually {{::data.article.text}}).

  • Add a <div> above it:

 

<div class="alert alert-info" ng-if="data.isInternal">
    <strong>NOTE:</strong> It is for Internal users only.
</div>
<div class="alert alert-warning" ng-if="!data.isInternal">
    <strong>NOTE:</strong> It is for external users only.
</div>
  • In the Server Script, add:
data.isInternal = $sp.getField(gr, 'u_internal_users'); // 'gr' is the GlideRecord for the article

 

Since you are a beginner my advice: Start with the Display Business Rule.  It is one script that solves both the Portal and the Preview requirement simultaneously with zero risk of breaking the Portal layout.

 

 

If this helped to answer your query, please mark it helpful & accept the solution.
Thanks!
Krishnamohan

 

 

 

Hi @KrishnaMohan ,

Thanks for responding!

I have already tried the Display BR, It is not allowing me to add Info message in the Service Portal. However I am getting it in the Native UI. And I tried with your script and conditions that you have given, I getting the same output. I have tried the 2nd possibility too, but no luck. Please find time to discuss this further. Thanks again.

@imranshaik0  

can you share your widget code (server code where you have add new line) or screen shots here