How to get data of attachments in flow design?

Sraj1
Giga Contributor

I have a catalog item where end user attach a txt file with some data on it.How can i get access of attachment data's in flow design?

1 ACCEPTED SOLUTION

Hi,

end user when attaches file to catalog during submission it gets attached to the RITM record.

From that you can use the Lookup attachment action and then the custom flow action

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

13 REPLIES 13

@Sraj 

Currently out of the box there is no direct action/step which would give you the Attachment content.

So you will have to create custom action for this and pass the attachment record sys_id to that action as input

The action would have script which would then query the sys_attachment and get the content and then set the output as this value

Refer sample script on how to get attachment content with attachment sys_id

(function execute(inputs, outputs) {

var sysId = inputs.sys_id;

  var attGr = new GlideRecord('sys_attachment');
  attGr.addQuery('sys_id', );
  attGr.query();
  if(attGr.next()){
   var gsu = (typeof GlideStringUtil != 'undefined') ? (GlideStringUtil) : (Packages.com.glide.util.StringUtil); //few versions support the first one, other supports second
   var gsa = (typeof GlideSysAttachment != 'undefined') ? (new GlideSysAttachment()) : (new Packages.com.glide.ui.SysAttachment());
   var attachmentData = gsa.getBytes(attGr);
   var attachment = String(Packages.java.lang.String(attachmentData));  
   
   outputs.duration = attachment;
})(inputs, outputs);
 

Refer below links for help on how to create custom flow action

Custom Action in ServiceNow Flow Designer

Creating a custom Event Action in Flow Designer

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I do not have file name as file is uploaded by end user.So, i dont think i can use look up attachment action.

Hi,

end user when attaches file to catalog during submission it gets attached to the RITM record.

From that you can use the Lookup attachment action and then the custom flow action

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

you are awesome.Thank you.

Hi, Ankur when i create a catalog item with attachment variable, from the attachment to group table through servicenow using flow designer. If the excel attachment is attached with group member and group name then need to load the data into servicenow group member table using the flow designer. can you please help to achieve it