Download attachment from KB article when click on a UI action
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2024 04:51 AM
HI,
I have an UI action Incident table list view. Whenever i click on the UI action it should download the attachment present in KB article. The KB article has only one attachment
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2024 05:59 AM
Hi there @tanz
create a new UI action for the Incident table list view.
Then set the action name, client script, and other properties
For the Action name, use something like "Download KB Attachment".
nOW write a client script that fetches the attachment URL from the KB article and initiates the download.
function downloadAttachmentFromKB() {
var kbArticleSysId = g_form.getValue('knowledge_base');
if (kbArticleSysId) {
var gr = new GlideRecord('kb_knowledge');
if (gr.get(kbArticleSysId)) {
var attachmentSysId = gr.getValue('u_attachment_field'); /
if (attachmentSysId) {
var attachment = new GlideSysAttachment();
var file = attachment.getContentStream(attachmentSysId);
if (file) {
d
var a = document.createElement('a');
a.href = window.URL.createObjectURL(file);
a.download = attachment.getFileName(attachmentSysId);
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
alert('Attachment not found or cannot be downloaded.');
}
} else {
alert('No attachment found in the KB article.');
}
} else {
alert('KB article not found.');
}
} else {
alert('No KB article selected.');
}
}
Latly add the UI action,
If this helps kindly upvote and accept the response thanks much.
☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India