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.

How to read JSON attachment of more than 5 MB size, in Scoped Application?

Mahesh Bachhav
Kilo Expert

getContent() is unable to read the attachment content if the attachment size is more than 5 MB. How to read JSON attachment content as a string if the JSON attachment is more than 5 MB? 

1 ACCEPTED SOLUTION

Mahesh Bachhav
Kilo Expert

I have solved the problem using getContentStream() and readLine() of GlideTextReader. I am able to read more than 5 MB of data.

var is = new GlideSysAttachment().getContentStream(attachmentSysId);
var reader = new GlideTextReader(is);
var ln = ' ';
while((ln = reader.readLine()) != null) {
  gs.info(ln);
}

 

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I believe for that you would require to use mid server as max size to read is 5MB

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Mahesh Bachhav
Kilo Expert

I have solved the problem using getContentStream() and readLine() of GlideTextReader. I am able to read more than 5 MB of data.

var is = new GlideSysAttachment().getContentStream(attachmentSysId);
var reader = new GlideTextReader(is);
var ln = ' ';
while((ln = reader.readLine()) != null) {
  gs.info(ln);
}

 

Would you mind sharing complete script?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader