Skip to Content

Text file import in Jitterbit App Builder

This C# plugin takes a txt file and inserts each line as a record to a staging table as a string in target column.

C:\ is the source local directory the txt file exists at importTableIDText takes a GUID to the TableID the text will be targeted into "FileName" is the column name in BO Event is run from to select particular file in source local directory "Import" is the column name in the target Table each line will be saved as a new record with a string of its content in this column.

Use case

This could be used when the business has a fixed-width or fixed format text file that needs to be imported to bring the data into App Builder to a staging table, before using additional business logic to parse the data into appropriate fields for later business processes.

Plugin references

Column Data Type Description
C: String source local directory
importTableIDText Unique ID takes a GUID to the TableID the text will be targeted into
FileName String column name in Business Object Event is run from to select particular file in source local directory
Import String column name in the target Table each line will be saved as a new record with a string of its content in this column

Text file import script

using System;
using System.IO;
using Vinyl.Sdk.Events;
using Vinyl.Sdk.Filtering;
// the directory to read files from
const string directory = @"C:\";
// the tableid to import the data into
const string importTableIDText = "cfeb9762-10c8-4832-ba9d-446ba0b39e8a";
// File to be imported
// This column should be present in the data object triggering this plugin
string fileName = Row["FileName"].GetValueAsString();
Guid importTableId = new Guid(importTableIDText);
var tableService = Services.GetService<ITableService>();
var eventService = Services.GetService<IEventService>();
// Creates EventTable (2.6 is missing a function to go from Table
// to EventTable w/o using an event, so we limit to 0 rows to avoid
// wasting time bringing rows we don't need)
var importTableFilter = tableService.GetTable(importTableId).CreateFilter();
importTableFilter.Limit = 0;
var importTable = await eventService.InvokeFilterEventAsync(importTableFilter);
foreach (string line in File.ReadLines(Path.Combine(directory,fileName)))
{
    // Creates a new row in the staging table
    EventRow row = await eventService.InvokeNewEventAsync(importTable);
    // Pull the desired values
    row["Import"].Value = line;
    // Inserts (persists) that row
    await eventService.InvokeInsertEventAsync(row);
}