
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 12:19 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 03:27 AM
Hi
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 12:52 PM
Take a look at this community post:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 01:05 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 03:27 AM
Hi
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2019 11:57 AM
Yes! This is correct. I should have updated this post once I got an answer from HI. They have it documented under PRB1364356 / KB0780785.