The CreatorCon Call for Content is officially open! Get started here.

Editing CSV attachment before loading to data source

RyanPSchneider
Tera Expert

We have an emailed CSV attachment that we want to load and map to our environment but the first three /r/n prevent us from being able to load the data in.

 

Has anyone made a custom flow designer action or script that can remove the first X lines from a CSV attachment inbound?

1 ACCEPTED SOLUTION

nityabans27
Giga Guru

Hi @RyanPSchneider,

 

Approach: Flow Designer Custom Action to Strip First X Lines

Inputs:

  • attachmentSysId → sys_id of the CSV attachment

  • linesToSkip → number of lines to remove (e.g., 3)

Outputs:

  • cleanedCSV → CSV string with header/junk lines removed

Server-side Script (example):

(function execute(inputs, outputs) {
var gsa = new GlideSysAttachment();
var bytes = gsa.getBytes(inputs.attachmentSysId);
var content = Packages.java.lang.String(bytes, "UTF-8"); // convert to string

// Split into lines, handle both \r\n and \n
var lines = content.split(/\r?\n/);

// Remove first X lines
var cleaned = lines.slice(parseInt(inputs.linesToSkip, 10)).join("\n");

// Return cleaned CSV as output
outputs.cleanedCSV = cleaned;
})(inputs, outputs);

 

🔄 How to Use in a Flow

  1. Flow trigger → e.g. Inbound Email with attachment.

  2. Custom Action (above) → input = attachment sys_id, linesToSkip = 3.

  3. Use cleanedCSV output in your next step:

    • Write back to a new attachment, or

    • Parse directly with your CSV parser/import logic.

View solution in original post

5 REPLIES 5

Hi @RyanPSchneider ,

Good to know the solution worked and you thought of helping others as well.