We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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

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  ||  10x 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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader