- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 04:52 AM
Hello,
I've a requirement to read the inbound email with attachment in flow and I'll get list of users in attachment and read the attachment line by line and activate the user by checking active field in user table for the user record.
This should happen completely through flow.
Is there any action that handles this situation? Do let me know if you need more info.
Thanks,
Kishore.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 07:02 AM
yes , you will have create flow with inbound email trigger, then create script action to get attachment table. After that you can read attachment by converting data in bytes
Sample Script
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', recordID);
attachment.query();
if ( attachment.next() ) {
var attachID = attachment.sys_id;
var attach_data = new GlideSysAttachment();
var by_data = attach_data.getBytes(attachment);
read_data = Packages.java.lang.String(by_data);
}
After that you need to process read_data as per your requirement.
If you find this answer helpful please don't forget to mark it Helpful. Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 07:02 AM
yes , you will have create flow with inbound email trigger, then create script action to get attachment table. After that you can read attachment by converting data in bytes
Sample Script
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', recordID);
attachment.query();
if ( attachment.next() ) {
var attachID = attachment.sys_id;
var attach_data = new GlideSysAttachment();
var by_data = attach_data.getBytes(attachment);
read_data = Packages.java.lang.String(by_data);
}
After that you need to process read_data as per your requirement.
If you find this answer helpful please don't forget to mark it Helpful. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 12:32 AM
How can we loop through each line from the variable?
In this case 'read_data' variable having data, can we go through line by line?
If we can loop through then I wanted to add each line value to an array and the array will be used in next step of flow to update a record.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 12:56 AM
it depends on your attachment type whether it is doc , excel,csv etc. You can print read_data variable on basis of rendered data you can split. For example for CSV you can use line break to seperate all line then use a for loop and you can read each line individually and process data further using "," as a delimiter. after that you can pass required data by creating an array in output variable of script action. Then you can map that script output with action output which can be used in next step of flow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 05:25 AM
Can you tell me what's the issue with below script
(function execute(inputs, outputs) {
var counter = 0;
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.get('table_sys_id', inputs.recId);
var ga = new GlideSysAttachment();
var base64EncodedData = GlideBase64.encode(ga.getBytes(grAttachment));
var fileData = GlideStringUtil.base64Decode(base64EncodedData);
var fLines = fileData.split(",");
outputs.content = fLines;
outputs.counter = fLines.length;
//foreach(var line in fileLines){
for (var i = 1; i < fLines.length; i++){
outputs.filelines.push(fLines[i]);
}
})(inputs, outputs);
CSV:
Do let me know if you need any other information