- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2019 04:31 AM
****I want to download selected files from incident instead of all could you please help with the script***
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2019 07:44 AM
Hi Krishna,
So here is the updated UI page code which shows checkbox besides every file; you need to click the checkbox for which file to be downloaded
then click on the download attachments and it will download
UI Page Code:
<?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 recordSysId = RP.getWindowProperties().get('sysparm_sysID');
var arr = [];
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', recordSysId);
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>Download Yes/No</th>
<j:forEach items="${jvar_jsonObj}" var="jvar_json">
<tr><td>${jvar_json.name}</td><td><input class="checkbox" type="checkbox" name="type" id="${jvar_json.path}"></input></td></tr>
<!-- <a href="${jvar_json.path}">Click here to download this file</a> -->
</j:forEach>
</table>
<button type="submit" value="download_attachments" onclick="downloadFiles()">Download Specific Attachments</button>
</j:when>
<j:otherwise>
<p>No attachments to display</p>
</j:otherwise>
</j:choose>
</j:jelly>
Client Script Code:
function downloadFiles(){
var selected = [];
$j("input:checkbox[name=type]:checked").each(function() {
selected.push($j(this).attr('id'));
});
for(var i=0;i<selected.length;i++){
var url = selected[i];
window.open(url);
}
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 03:16 AM
Hi Ankur,
I have tried in all the browsers and it's not allowing to download two files and i am trying in person instance.Please find below details can you please check
https://dev61243.service-now.com
admin
Pwd:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 05:41 AM
Hi Ankur Did you able to get a chance to check on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 08:29 AM
Hi Krishna,
not yet will check and keep you posted.
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
09-27-2019 08:58 AM
Hi Krishna,
I checked in your instance and here is the screenshot of the testing from my side
Browser Used: Chrome
1) opened incident - INC0010405
It has 3 attachments
2) I have checked Capture.PNG and Capture1234.PNG
3) when I click on Download Specific Attachments; it downloaded 2 files
screenshot below showing alert of 2 files
screenshot showing 2 attachments downloaded automatically
my chrome download settings showing auto download; if you enable it then it will ask you before downloading where to save
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2019 12:05 AM
Now i can download the selected files and i am close to achive my requirement and need your help post clicking download option and i am getting sys id's popup.could you please help to remove those sys id's tp download selcted files.
Thanks for putting lot of time ankur