4 Replies · Latest reply on Nov 22, 2017 6:23 AM by Gopinath L

    ISSUE in SENDING ATTACHMENTS

      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?