Skip to Content

Scripting example in Jitterbit App Builder - Text file creation

This plugin will create a text file, using values from a column (string) from a tableID as each line of text. tableIdstring is tableID GUID of Source Business Object "exportColumnName" is the column name which is source column for each line of text "fileName" is a column in Business Object running event with the desired name of file "exportFileName" is the full path and filename desired for created file.

// Sample binding… shows an example beneath it for a filter that can be used in similar manner an App Builder bind would work on a link to a Crystal Report page to filter results of source Business Object.

Use case

This could be used when the business needs to create a fixed-width or fixed format text file to be shared with ADP or another service by this means.

Plugin references

Column Data Type Description
tableIdstring Unique ID tableID GUID of Source Business Object
exportColumnName String column name which is source column for each line of text
fileName String column in BO running event with the desired name of file
exportFileName String full path and filename desired for created file

Text file creation script

using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Vinyl.Sdk.Filtering;
// The TableId that points to the business object that will return the data we want to export
var tableIdString = "fdfa87fd-06df-4436-bcf4-1126525ab385";
// The column we are going to export - this could come from Action Row if desired
var exportColumnName = "String";
// This pulls in the filename for the Path from Event's BO
string fileName = Row["fileName"].GetValueAsString();
// The file we are writing out - this could come from Action Row if desired
var exportFileName = @"C:/App Builder Files/DEBTS_PRL/" + fileName;
// read user/password from table and create token
var eventService = Services.GetService<IEventService>();
var tableId = new Guid(tableIdString);
var filter = Services.GetService<FilterBuilder>()
    .From(tableId);
filter.Filter.Limit = 10000;
// Sample binding...
// filter.Where("Country",ComparisonOperator.Equals,"USA");
var lines = new List<string>();
EventTable outputTable = await eventService.InvokeEventAsync(filter,"filter");
foreach(var row in outputTable.Rows)
{
   lines.Add(row[exportColumnName].Value.ToString());
}
System.IO.File.WriteAllLines(exportFileName,lines);