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.

Illegal access to method writeTo(java.io.ByteArrayOutputStream) in class com.glide.ui.SysAttachmentInputStream

cloudyrobert
Kilo Guru

Getting this error when I run the following script in New York P1/HF1:

var attachmentIS = new GlideSysAttachmentInputStream('SYS_ID_OF_ANY_ATTACHMENT');
var bytearrayOS = new Packages.java.io.ByteArrayOutputStream();
attachmentIS.writeTo(bytearrayOS);

 

Error:

Attempted script access to inaccessible member denied - com.glide.ui.SysAttachmentInputStream:writeTo:(Ljava/io/OutputStream;)V
Evaluator: java.lang.SecurityException: Illegal access to method writeTo(java.io.ByteArrayOutputStream) in class com.glide.ui.SysAttachmentInputStream
   Caused by error in script at line 3

      1: var attachmentIS = new GlideSysAttachmentInputStream('f7ecf6dd1b208c50791aea866e4bcb19');
      2: var bytearrayOS = new Packages.java.io.ByteArrayOutputStream();
==>   3: attachmentIS.writeTo(bytearrayOS);

Background message, type:error, message: Illegal access to method writeTo(java.io.ByteArrayOutputStream) in class com.glide.ui.SysAttachmentInputStream

 

Anybody seen this? I don't see any replacements for Packages.java.io.ByteArrayOutputStream if that's the issue.

Edit: Global scope.

1 ACCEPTED SOLUTION

Sebastian R_
Kilo Sage

Hi @relliott ,

I found the solution for your problem. Looks like ServiceNow has changed a little bit. OOTB example in sys_script.do?sys_id=468eebfeff447300c2e8a897d53bf16e.

sa = new GlideSysAttachmentInputStream(saGr.sys_id);
content = new Packages.java.io.ByteArrayOutputStream();
sa.writeTo(content, 0, 0);
content.close();

You have to use attachmentIS.writeTo(bytearrayOS, 0, 0);

 

View solution in original post

6 REPLIES 6

Hi Sebastianreinmann, 

I have the similar issue of sending >5MB attachments to the thrid party system through SOAP web service integration. I have tried the above code you mentioned, it was working fine and I was able to successfully send the attachments of 5.3 MB or 5.4MB but I could'nt send >7MB. Is there any size limitations on using Packages.java.io.ByteArrayOutputStream(). Currently I am on NY patch 2. 

Any recommendations would be appreciated. 

Hello All,

I've made the change "attachmentIS.writeTo(bytearrayOS, 0, 0);" to my script include, the error does not happen but the attached file does not go when the case is save and the BR run. Is there anything I should look for?

Thanks,