ERROR : com.glide.ui.SysAttachment@1532ed9 Couldn't decipher the stack trace resulting from the fol

Rahul Tiwari1
Tera Contributor

i am getting error : 

com.glide.ui.SysAttachment@1532ed9
Couldn't decipher the stack trace resulting from the following JavaScriptException:
var myAttach = new GlideSysAttachment();
//var myAttach = new GlideSysAttachment();
             var s_Attach = new GlideRecord('sys_attachment');//sys_attachment
s_Attach.addEncodedQuery('file_name=abcd.csv');
              s_Attach.orderByDesc('sys_created_on');

  s_Attach.setLimit(1);
             
             s_Attach.query();
             if(s_Attach.next()){
                //var filename=s_Attach.file_name;
                var sys=s_Attach.sys_id;
             }
             //gs.print("the value of sysid is :"+filename);
             gs.info("the value of sys "+sys);
var copyFileName = 'abcd.csv';
var copyFileType = 'application/csv';
var copyContent = '';
var copySysId = sys; //
gs.info("the sysid is :" + copySysId);
var mostRecentDate = new GlideDateTime();
var recenttime=mostRecentDate.getDisplayValue().split(' ')[1];
gs.info("the mostRecentDate is :" + recenttime);
var timeFound = true;

//myAttach.get(copySysId).tostring();

var incAttach = myAttach.getAttachments('sys_attachment', copySysId);
if (incAttach.next()) {
   // if (!timeFound || recenttime < incAttach.sys_created_on) {
    if(recenttime <= incAttach.sys_created_on){
       // recenttime = incAttach.sys_created_on;
        copyFileName = incAttach.file_name;
        copyFileType = incAttach.content_type;
        copySysId = incAttach.sys_id;
    }
}

var contentStream = myAttach.getContentStream(copySysId);

gs.print("content: "+myAttach);
var createAttachment = new GlideSysAttachment();
createAttachment.writeContentStream(current, copyFileName, copyFileType, contentStream);

 

5 REPLIES 5

@Rahul Tiwari1 GlideSysAttachment() works in both Global and Scoped applications. Here the ServiceNow document covering the same https://docs.servicenow.com/en-US/bundle/utah-api-reference/page/app-store/dev_portal/API_reference/...

 

Please accept my solution as correct answer and mark it as helpful.