Notifications

53 views

Description

User when trying to send multiple attachments as a array of objects, if they try to send two different attachments in output it shows both the attachments are having the same name but different content.

Script to parse the attachment and output the information:

 inputs = {};
inputs.IncSysId = '84c2e556dbe49050a865bc23e2961923';
outputs = {};
execute(inputs, outputs);

function execute(inputs, outputs) {

//Attachments code
var attachStr;
var attachments=[];
outputs.attachments=[];
var i=0;
var attachRec = new GlideRecord('sys_attachment');
attachRec.addQuery('table_sys_id', inputs.IncSysId);
attachRec.addQuery('table_name', 'incident');
attachRec.query();

while(attachRec.next()) {
var sa = new GlideSysAttachment();
var StringUtil = new GlideStringUtil();
var attachobj={"attachment":{}};
var fileName=attachRec.file_name;
var fileContent=attachRec.content_type;
var binData = sa.getBytes(attachRec); 
var encData = StringUtil.base64Encode(binData);
outputs.attachments.push(attachobj);
outputs.attachments[i].attachment.attachmentFileName = fileName;
outputs.attachments[i].attachment.attachmentFileType = fileContent;
outputs.attachments[i].attachment.attachmentContent= encData;

i++;
}
gs.print('0 ' + outputs.attachments[0].attachment.attachmentFileName);
gs.print('1 ' + outputs.attachments[1].attachment.attachmentFileName);

// outputs.attachments=attachments;
outputs.priority=inputs.IncRecord.priority;
outputs.category=inputs.IncRecord.category;
outputs.subcategory=inputs.IncRecord.subcategory;
outputs.contact_type=inputs.IncRecord.contact_type;
outputs.state=inputs.IncRecord.state;

}

Release or Environment

Any Version

Cause

Issue with the JavaScript Code

Resolution

Need below changes to the script :

  var fileName=attachRec.file_name;
   to:
  var fileName=attachRec.file_name.toString();

  var fileContent=attachRec.content_type;
   to:
  var fileContent=attachRec.content_type.toString();

With out this change the type of both variables are "object" not "string" which is resulting the issue with the output content.

Article Information

Last Updated:2020-05-17 22:50:04
Published:2020-05-18