Should I add article template or UI macro script for existing articles?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 12:51 AM
Hi all,
I have a requirement to add an additional field to all articles in a particular knowledge base. The field should appear as part of the article but only be visible to itil users.
I understand that article templates are considered standard now, but it is not clear to me how I can apply a new article template to all already existing articles in the knowledge base. There is no "Article template" field on a knowledge article where you can decide what template it belongs to. So instead I am considering the following:
1. Create a new text field on the kb_knowledge table with a read ACL set to itil.
2. Find the UI macro that the the articles use (this is proving difficult - it is apparently not kb_view_common_content, because nothing changes even if I comment out that whole file).
3. Add a code snippet in the correct UI macro in accordance with this blog post:
If anyone knows how I can solve this either with the article template approach or with the UI macro approach it would be much appreciated.
/Kim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 02:01 AM
Follow this Support Article to achieve this:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0955875
Just replace u_myCustom_html_field with the name of your custom field and also add an ACL for the 'itil' role on the field
- The custom fields on the knowledge article are not displaying
- how to display them
Instructions
- Navigate to System UI > UI Macros.
- Search for a macro, Name = kb_view_common_content, and open this record
- Insert the following line
$[NS:knowledgeRecord.u_myCustom_html_field] - In between the following div tag And make sure to replace
- ->u_myCustom_html_field
->with the database field name that you copied in step 5.
->Click 'Update' down below. - The custom field will now be visible when viewing Knowledge articles.
Regards
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 07:04 AM
Hello Kim, I feel like you are asking two questions.
- How do I add a field to an existing template: add an additional field to all articles in a particular knowledge base.
- Create a new template and apply it to existing articles: How I can apply a new article template to all already existing articles in the knowledge base.
If you are attempting item #1, I think Paul's answered the question. For item 2, you must work with your devs to create a script.
Please note there's an Idea under consideration to allow changing templates. If this is something you would like to see, please log in and vote for it!
https://support.servicenow.com/now?id=view_idea&sysparm_idea_id=9c404596db8ee890679499ead396196f&sys...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2024 03:51 AM
I want to add that if I were to go with 2), creating a script, I am the dev who would implement that. But I don't understand how, since I don't understand where the article template is connected to the kb_knowledge record. I can see that article template fields are added directly to the kb_knowledge table, which means it would be no difficult to set the value of an article template field based on the article's body text field. But that doesn't change the template of the existing article, and I don't see where to do that.
/Kim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 07:20 AM
@Paul Curwen and @Kim27, thank you for your suggestions:
Paul, I have read that article you linked to and according to me it is not intelligible, as the "following div tag" does not come up in the instructions and also it is unclear what step 5 refers to. Almost as if the article had been cut off somehow. In any case, as I wrote in my initial post, nothing happens even if I comment out the whole kb_view_common_content UI macro. Existing knowledge articles are rendered exactly as before.
Kim27: Well, I'm not exactly asking 1) because I know how I can add a new field to an article template. Rather, what I am considering now is to ignore article templates entirely and simply create a new field on the kb_knowledge table. The field can have an ACL and also be connected to a particular view that is only available to one ServiceNow group. But then I need to find the UI macro that determines what fields are being rendered as part of an article and to work with that.
/Kim