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

Thanks--yeah, I'm familiar with the general migration away from Packages calls and motivation for doing so. I don't see any replacement for this API in the global scope, however, and unfortunately, this app's already there in global.

Best solution I can come up with so far is to create a utility scoped app that allows access from global in order to make calls to the scoped API from a global context.

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);

 

Yes! This is correct. I should have updated this post once I got an answer from HI. They have it documented under PRB1364356 / KB0780785.