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

Sandeep Rajput
Tera Patron
Tera Patron

Try the following script.

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();
var sys = ''
if (s_Attach.next()) {
    //var filename=s_Attach.file_name;
    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);

Tahnks @Sandeep Rajput  for response ,

still same error : "

Evaluator.evaluateString() problem: com.glide.script.fencing.MethodNotAllowedException: Function print is not allowed in scope 

"

@Rahul Tiwari1 This time error is different then the previous one but here is the fix for the latest error.

 

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();
var sys = ''
if (s_Attach.next()) {
    //var filename=s_Attach.file_name;
    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.info("content: " + myAttach);
var createAttachment = new GlideSysAttachment();
createAttachment.writeContentStream(current, copyFileName, copyFileType, contentStream);

Hope this helps.

Thanks @Sandeep Rajput  for response ,

 Is there any way to replace 

new GlideSysAttachment()

 for scope application