- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 08:01 AM
As per the Subject - is the service able to open the pdf attached to the article directly within the viewer without downloading it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 11:38 AM
HI @Flitdog78 ,
Hope you are doing great.
Yes, it is possible to open a Knowledge Article directly to the attachment without opening the article in ServiceNow.
1. Create a UI Action: Go to "System Definition" > "UI Actions" and create a new UI Action with the following settings:
Table: kb_knowledge (Knowledge Article table)
Action name: open_attachment_directly
Client: true
2. Navigate to "System Definition" > "UI Scripts" and create a new UI Script with the following code:
function openAttachmentDirectly() {
var knowledgeSysID = g_form.getValue('sys_id'); // Get the current Knowledge Article's sys_id
var attachmentSysID = g_form.getValue('u_attachment_field'); // Replace 'u_attachment_field' with the actual field name storing the attachment sys_id
if (attachmentSysID) {
var attachmentUrl = new GlideURL('sys_attachment.do');
attachmentUrl.addParam('sys_id', attachmentSysID);
attachmentUrl.addParam('sysparm_referring_url', 'kb_knowledge.do?sys_id=' + knowledgeSysID);
window.open(attachmentUrl.getURL());
} else {
alert('No attachment found.');
}
}
3. Add the UI Action to the form layout: Edit the form layout of the Knowledge Article table (kb_knowledge) and include the newly created UI Action, "Open Attachment Directly."
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 06:24 AM
Hi @Flitdog78
Greetings!!
even though solution has been accepted but i have point here,
- What is business case of this requirement?
- Instead of coding / scripting lets try to find out is any alternative for this or not.
Please mark my answer helpful or solution accepted if it serves the purpose.
Regards
Atul G
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 06:44 AM
The business requirement is that some of our staff don't like to open the download when clicking on the article. They would prefer to go direct into the attached document.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 07:20 AM
We edit the kb article source to include the document viewer in an iframe:
<p><iframe src="/$viewer.do?sysparm_stack=no&sysparm_sys_id=5f6493b31b6fe5149e4e8663cc4bcb6e" width="100%" height="1000" allowfullscreen="allowfullscreen"><span id="mce_12"></span></iframe></p>
Please note that you will need to update the sys_id in the code with the attachment you want to display's sys_id.
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 07:55 AM
Have tried this Dave. Much appreciated Sir, But I keep coming away with an empty page when I save the code in the document it's fine
But afterwards it just goes blank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 10:32 AM
My guess is that HTML Sanitization is on for that field.