Need to download selected files from the attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 01:13 AM
I am using OOB functionality Attachments related list and i cannot able to download selected files,when i download those specific files it's downloading all the files other than the selected files.PFB
Could you please provide the script to download specific files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 01:29 AM
Hi Krishna,
I remember similar question from you earlier to which I posted solution
Can you share the code for the Download UI action?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 02:15 AM
Hi Ankur,
Earlier requirement was different.Now i want the option in attachment related list to download selected files.Could you please help me with code ankur.
Thanks,
Pratheep A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 02:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 04:35 AM
Hi Krishna,
Similar things you can do here; there in UI action you were calling UI page and sending the record sys_id to get the attachment records
Now here since you already have the attachment records added as related list; the list choice UI action can pick the record sys_ids directly
Update the UI action as below; you will send the checked records sys_ids now
function openPage(){
var sysIdArray = g_list.getChecked();
var gDialog = new GlideDialogWindow("show_attachments");
gDialog.setTitle("Display & Download Attachments");
gDialog.setSize(800,800); //Set the dialog size
gDialog.setPreference('sysparm_checkedValues', sysIdArray.toString());
gDialog.render();
}
UI page updated code: now you will query sys_attachment table with the sys_id of the records and then iterate over it
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<g:evaluate jelly="true" object="true" var="jvar_jsonObj">
var recordArr = RP.getWindowProperties().get('sysparm_checkedValues');
var arr = [];
var gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', 'IN' , recordArr);
gr.query();
while(gr.next()){
var jsonObj = {};
jsonObj.name = gr.getValue('file_name');
jsonObj.path = '/sys_attachment.do?sys_id=' + gr.getValue('sys_id');
arr.push(jsonObj);
}
arr;
</g:evaluate>
<j:choose>
<j:when test="${arr.length > 0}">
<table cellspacing="0" cellpadding="0" width="100%">
<th>File Name</th>
<th>Path</th>
<j:forEach items="${jvar_jsonObj}" var="jvar_json">
<tr><td>${jvar_json.name}</td><td><a href="${jvar_json.path}">Click here to download this file</a></td></tr>
</j:forEach>
</table>
</j:when>
<j:otherwise>
<p>No attachments to display</p>
</j:otherwise>
</j:choose>
</j:jelly>
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader