- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 10:19 PM
Hi Team.
I would like to use the JSZip library to collect attachments attached to a table into a Zip file.
I created "JSZip" using the code from the jszip.js file as a script include.
I am calling a Script Include "CreateZip" in a UI Action "Demo Zip" and calling "JSZip" on that Script Include.
This will cause no error and nothing will happen. Please let me know if there is a correct way.
UI Action「Demo Zip」
function onClick() {
var ga = new GlideAjax('CreateZip');
ga.addParam('sysparm_name','createZip');
ga.getXML(ManagerParse);
function ManagerParse(response) {
alert('A');
}
}
Script Include「CreateZip」
var CreateZip = Class.create();
CreateZip.prototype = {
initialize: function() {},
createZip: function() {
var ga = new GlideRecord('sys_attachment');
ga.addQuery('table_name', 'u_demo_table');
ga.query();
// Initialize JSZip
var zip = new JSZip();
while (ga.next()) {
// Add files to the zip
var file = new GlideSysAttachment().getContentStream(ga);
var fileName = ga.getValue('file_name');
zip.file(fileName, file);
}
// Generate the zip file
zip.generateAsync({
type: "blob"
}).then(function(content) {
// Create a download link for the zip file
var link = document.createElement("a");
link.href = URL.createObjectURL(content);
link.download = "table_data.zip";
link.click();
});
zip.generateAsync({
type: "blob"
})
.then(function(blob) {
saveAs(blob, "hello.zip");
});
},
type: 'CreateZip'
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 11:44 PM
as already answered by me, it makes no sense to continue. Your given code contains JavaScript promises (.then()) which cannot work in ServiceNow as your Script Include seems to be created in the global scope thus using the old ES5 engine. Further I read something like "generateAsync". Also this cannot work on server-side as ServiceNow has no nodeJS engine and any asynchronous approaches have to be implemented with OOTB means.
Don't waste your time!
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 10:33 PM
so what's the error?
ServiceNow has inbuilt flow step for this. Did you check that?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 11:39 PM
Thank you for your reply.
The error code is as follows.
<table_list>.do%3Fsysparm_userpref_module%3D615288a983d03550e7b771647daad32e:1 The resource <instance>.service-now.com/uxasset/set-cache-buster/1704632735275.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 11:44 PM
as already answered by me, it makes no sense to continue. Your given code contains JavaScript promises (.then()) which cannot work in ServiceNow as your Script Include seems to be created in the global scope thus using the old ES5 engine. Further I read something like "generateAsync". Also this cannot work on server-side as ServiceNow has no nodeJS engine and any asynchronous approaches have to be implemented with OOTB means.
Don't waste your time!
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 10:35 PM
It doesn't appear that you've marked your CreateZip script include as "client callable". If it is, you need to ensure that you extend it from global.AbstractAjaxProcessor:
CreateZip.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {