Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
Issue with Attachments output variables in flow designer actions - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • Issue with Attachments output variables in flow designer actions
KB0825333

Issue with Attachments output variables in flow designer actions


1020 Views Last updated : Apr 8, 2024 public Copy Permalink
KB Summary by Now Assist

Issue

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

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.


The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.