- 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
- 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;
- 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