Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Create new empty attachment, with no content

Ram_n Botelho
Tera Contributor

Hi.

I am trying to create a new empty file, with no content, but the following method only works if content is filled.

Does anyone have any idea of how can I get it, please?

 

var attachment = new GlideSysAttachment();
attachment.write(grTask, fileName, 'text/plain', content);
2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

I have gotten this to work using ' ' (one space) as the final argument.  There's probably a Business Rule, System Property, or check in the script method preventing 0 byte file sizes.

Rafael Batistot
Kilo Patron

hi @Ram_n Botelho 

If you really want to create a file with no content (0 bytes), you can do it like this:

 
var attachment = new GlideSysAttachment();
var emptyContent = ''; // nothing inside
attachment.write(grTask, fileName, 'text/plain', emptyContent);

 

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.