ISSUE in SENDING ATTACHMENTS

trimbakesh_madh
Kilo Contributor

Hi Guys,
I am trying to send the attachments through web services and i am using the following business rule
var StringUtil = Packages.com.glide.util.StringUtil;

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('table_name', current.getTableName());

var fil = gr.file_name;
var typ = gr.content_type;
gr.query();

if (gr.next()){
var sa = new Packages.com.glide.ui.SysAttachment();
var binData = sa.getBytes(gr);
var encData = StringUtil.base64Encode(binData);
gs.log(encData,'encoded');
}
else{
gs.log('record not found');
}
var s = new SOAPMessage('test_attach1', 'insert');
s.setParameter('name',fil+":"+typ);
s.setParameter('payload',encData);
s.setParameter('topic', 'AttachmentCreator');
s.setParameter('source', "incident:"+current.sys_id);
s.setParameter('agent', 'AttachmentCreator');
var response = s.post();
gs.log(response,'AT109');

But when the business rule is executed in the system logs the evaluator is throwing the following error:

java.lang.SecurityException: Illegal attempt to access class 'com.glide.ui.SysAttachment' via script
Caused by error in Business Rule: 'ATTACHMENT' at line 12

9: gr.query();
10:
11: if (gr.next()){
==> 12: var sa = new Packages.com.glide.ui.SysAttachment();
13: var binData = sa.getBytes(gr);
14: var encData = StringUtil.base64Encode(binData);
15: gs.log(encData,'encoded');

Why am I getting this error?Is there any ways to get the access to the 'com.glide.ui.SysAttachment' class?

4 REPLIES 4

adiddigi
Tera Guru

I'm guessing you are on Calgary and hence any Package calls won't work, Do let me know if you aren't and you still are getting the error.

If you are on Calgary, replace


Packages.com.glide.ui.SysAttachment
with

GlideSysAttachment
and

Packages.com....StringUtil
with

GlideStringUtil


Thanks Abhiram, that works perfectly!!!


Thanks Abhiram !! Faced the same issue and it worked perfectly




Thanks


Gopinath


Inactive_Use525
Kilo Contributor

I am getting the same issue. Illegal attempt to access class 'com.glide' via script



i am using helsinki developer instance