- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 11:55 PM
I got a requirement to show the attach button for the knowledge articles showing in the related search based on user having access to the knowledge article.
I have tried with the UI action visibility by using the below script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 05:28 AM
Hi @EzhilB
please accept the solution .. and mark as helpful
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 12:07 AM
Hi @EzhilB
-
Retrieve the Knowledge Article and Requester:
Use the sys_id of the knowledge article and the requester's sys_id from the incident. -
Check Access:
Use the KBKnowledge API's canRead() method with the user_id parameter to check access. -
Set Visibility:
Determine if the Attach button should be shown based on the access check.
Updated Script :-
var kbArticleSysId = resource.sys_id; // sys_id of the knowledge article
var requesterSysId = current.caller_id; // sys_id of the requester (incident caller)
function hasAccessToKnowledgeArticle(kbSysId, userSysId) {
var kbGr = new GlideRecord('kb_knowledge');
if (kbGr.get(kbSysId)) {
// Check if the user has access to the knowledge article
return new KBKnowledge(kbGr).canRead(userSysId);
}
return false;
}
// Check access
var hasAccess = hasAccessToKnowledgeArticle(kbArticleSysId, requesterSysId);
// Set visibility
visible = hasAccess;
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 05:17 AM
Hi Ravi,
Thanks For your help it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 05:28 AM
Hi @EzhilB
please accept the solution .. and mark as helpful
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/