"Download all attachments in a single zip file" customization is creating issue

LearnerSubho
Mega Guru

Hello,

I have tried to configure a ui action to download all attachments in a single zip file.

I have taken help from servicenowguru : Download Attachments as a ZIP File - ServiceNow Guru

I am able to download the attachments in a single zip file but it is breaking some system functionalities (even for admins), such as :

  • Not able to personalize list of records through List mechanic. The slushbucket is not showing any field as available to add/remove.
  • Not able to open any workflow.
  • "Reset to column defaults" is not appearing through List mechanic.
  • on right click on any field it is not showing proper context menu.
  • not able to modify any data from list of records.


UI Action :

  • Show Insert , Show Update, Client : TRUE
  • Table : Task
  • Onclick : saveAttachmentsToZip();
  • Condition : current.hasAttachments();

//action.setRedirectURL('saveAttachmentsToZip.do?sysparm_sys_id=' + current.sys_id + '&sysparm_table=' + current.getTableName());

//action.setRedirectURL('sys_attachment.do?sys_id=' + current.sys_id + '&table_name=' + current.getTableName());

function saveAttachmentsToZip() {

  var url = new GlideURL('saveAttachmentsToZip.do');

  url.addParam('sysparm_sys_id', g_form.getUniqueValue());           //gel("sys_uniqueValue").value

  url.addParam('sysparm_table', g_form.getTableName());

  var frame = top.gsft_main;

  if (!frame)

  frame = top;

  frame.location = url.getURL();

}

I have tried only action.setRedirectURL (Line 1)...but facing same issue.

Processor :

  • Type : Script
  • Application Scope : Global
  • Parameters : sysparm_sys_id,sysparm_table [As expected, without parameters the ui action is not working]
  • Path : saveAttachmentsToZip

var sysid = g_request.getParameter('sysparm_sys_id');

var table = g_request.getParameter('sysparm_table');

var theRecord = new GlideRecord(table);

theRecord.addQuery('sys_id', sysid);

theRecord.query();

theRecord.next();

var zipName = 'attachments.zip';

var StringUtil = GlideStringUtil;

var gr = new GlideRecord('sys_attachment');

gr.addQuery('table_sys_id', theRecord.sys_id);

gr.addQuery('table_name', theRecord.getTableName());

gr.query();

if (gr.hasNext()){

      g_response.setHeader('Pragma', 'public');

      g_response.addHeader('Cache-Control', 'max-age=0');

      g_response.setContentType('application/octet-stream');

      g_response.addHeader('Content-Disposition', 'attachment;filename=' + zipName);

      //var out = new Packages.java.util.zip.ZipOutputStream(g_response.getOutputStream());

  var out = GlideZipOutputStream(g_response.getOutputStream());

      //var count=0;

      while (gr.next()){

              var sa = new GlideSysAttachment();

              //var binData = sa.getBytes(gr);

              var binData = sa.getContent(gr); /* getContent is limited to 5mb */

              var file = gr.file_name;

              this.addBytesToZip(out, zipName, file, binData);

              //count ++;

      }

      // Complete the ZIP file

      out.close();

}

function addBytesToZip (out, dir, file, stream){

      // Add ZIP entry to output stream.

      //out.putNextEntry(new Packages.java.util.zip.ZipEntry(file));

  out.putNextEntry(new GlideZipEntry(file));

      out.write(stream, 0, stream.length);

      out.closeEntry();

}

Issue snapshot :

Issue_for attachment customization.JPG

Once I am deactivating the processor, the issue is not there. Hence, the issue is causing due to the custom processor.

Please help me to rectify the issue.

Thanks.

11 REPLIES 11

LearnerSubho
Mega Guru

The customization is done on an instance which is having build version as 'Fuji - Patch 4'


Jacob_Andersen
ServiceNow Employee
ServiceNow Employee

I've tried using that SNGuru solution and it works great.   Here is a record in demo022 (Fuji) where I've applied the solution and it's working there, too.



https://demo022.service-now.com/nav_to.do?uri=incident.do?sys_id=d71f7935c0a8016700802b64c67c11c6



The processor would have nothing to do with your problem.   What you're seeing is a common problem when you have a syntax error in a client script.   I'd double-check your UI Action as it is running client-side.


Hello Jacob,



The solution is working perfectly fine, I am able to download attachments in zip file but it is conflicting with some of the system functionality (I guess) and giving me issues.



Note : To troubleshoot the issue, I just configured the processor, even didn't configure the UI Action.



Following are the issues with the processor (Script used : As shared in the post):


1. Not able to modify the filter in list of records (On click the filter button, its not showing the filter options)



issue -1.jpg


Able to see filters once the processor is inactive -


issue -2.JPG


2. Not able to add/remove fields in list of records through list mechanic once the processor is active.


issue -3.JPG



"Reset to column defaults" is not appearing too.



3. Workflow issue :


While the processor is active, system is not able to render workflow :


issue -4.JPG


When the processor is inactive,


issue -5.JPG



4. Not able to edit any field from list of record, when the processor is active.


Giving error as : No response from server - try again later


issue -6.JPG


FYI : I have also raised a 'hi' ticket for the issue but they are not able to help me and I had to close the ticket as they asked me to take help from their professional service as it is a customization. Their dev team kept the ticket on hold for long time to look into the issue thoroughly but no luck!



Warm Regards,


Subhankar


I also got a chance to test the customization in a dublin build instance but noticed the same issues.