Unzipping an attachment?

Mark Edwards3
Kilo Expert

We have a situation where an external source is providing us a zip file containing other related data files.  The requirement being that we then have ServiceNow unzip this file (stored as an attachment) and then store the contents (as attachments).

Is there any way from server-side script we can accomplish this?

We've spotted the GlideZipUtil, but can't figure out how to use it (or whether we can use it from script), so the best option we're currently looking at is to use a MID server script to pull the Zip file down to the file-system, unzip there and then push the contained files back all via REST.

Whilst that would work, it seems rather cumbersome and unnecessary when there may be an easier method within the platform itself.

 

I've had a trawl through the existing community comments, and there's really nothing of help in there (so please don't reply with the same set of external links to Stack Overflow ... we've seen them, and they're not really of much, if any help).

 

Cheers,
Mark

 

1 ACCEPTED SOLUTION

Dan Tolgyesi1
Tera Expert

Hi,

You could use a data source (System Import Sets>Data Sources) this has a "Zipped" checkbox which will unzip the attachment and load the data

Cheers

Dan

 

View solution in original post

5 REPLIES 5

Dan Tolgyesi1
Tera Expert

Hi,

You could use a data source (System Import Sets>Data Sources) this has a "Zipped" checkbox which will unzip the attachment and load the data

Cheers

Dan

 

Mark Edwards3
Kilo Expert

Thanks Dan.  That is eventually what we went with.  Shame that there seems to be no exposure to the scripting engine of the ability to Zip/Unzip files natively as whatever way we look at it, it's somewhat of a cumbersome hack.

Joe72
Tera Contributor

Great solution! The only downside to this is if there are any spaces in your zipped file names, this will fail. Trying to figure out a workaround...

This helped explain why this method of unzipping didn't work for me.

Were you successful with finding a workaround?