Gov Cloud - BPM to Create CSV on Network Drive - Help Needed

We need a way to export a CSV when a user marks a Customer Shipment Entry Header as “Ready to Invoice”. This file then needs to be deposited on our network at a specified location.

Currently, I have a Standard Data Directive under ShipHead that creates a StringBuilder and exports the data as an email. However, when I go to create a file and ship it to our location it bugs out and gives the following error:

Current Code:

// Create a list to hold the data
List<Tuple<String, int, int, String, decimal>> dataList = new List<Tuple<String, int, int, String, decimal>>();

// Loop through the returns and add each row of data to the list
foreach (var Line_iterator in (from e in Db.ShipDtl where e.Company == Company_c && e.PackNum == PackNum_C select e).ToList())
{
        var JobNum_C = Line_iterator.JobNum;
        var LineNum_c = Line_iterator.PackLine;
        var Pick_c = 2;
        var MaterialName_C = Line_iterator.PartNum;
        var Quality_C = Line_iterator.OurInventoryShipQty;
        

        Tuple<String, int, int, String, decimal> data = Tuple.Create(JobNum_C, LineNum_c, Pick_c, MaterialName_C, Quality_C);
        dataList.Add(data);
        

    
}

StringBuilder sb = new StringBuilder();

foreach (Tuple<string, int, int, string, decimal> row in dataList)
{
    for (int i = 0; i < dataList.Count; i++)
    {
        sb.Append(dataList[i]);
        
        // Add a tab character between columns, except for the last column
        if (i < dataList.Count - 1)
        {
            sb.Append("\t");
        }
    }
    
    // Add a new line character to move to the next row
    sb.AppendLine();
}

// Print the output to the console
//Console.WriteLine(sb.ToString());

//Email test
              var email = "Reciever email";
              var sender = "sender email";
              var emailMessage = sb.ToString();
             
              var body = emailMessage;
              var mailer = this.GetMailer(async: true);
              var messages = new Ice.Mail.SmtpMail();
              messages.SetFrom(sender);
              messages.SetTo(email);
              messages.Subject = "TEST";
              /*messages.SetCC();*/
              /*messages.SetBcc(); */
              messages.SetBody(body);
             
             mailer.Send(messages);


//File creation             
DateTime thisDay = DateTime.Today;             
//sb is a StringBuilder object that contains the CSV data
string csvFileName = "myCsvFile.csv";
string csvFilePath = @"NetworkLocation"+csvFileName;
// Create a StreamWriter object to write to the CSV file
using (StreamWriter writer = new StreamWriter(csvFilePath))
{
    // Write the contents of the StringBuilder object to the StreamWriter object
    writer.Write(sb.ToString());
    
    // Flush and close the StreamWriter object
    writer.Flush();
    writer.Close();
}

To use our BarTender, Epicor created a folder somewhere on their server (I’m assuming) that we can dump the files to. I would ask support to create a folder for your company to drop out these files and then you can monitor the folder and move the files to your network.

1 Like

Same. Epicor support created an FTP folder for us to send/receive files to.
Originally we just used it for Bartender but found that the BAQ export can run a query and export the results to the same folder which is handy for automation.

Now if I run server side BPM code can I access any files that I write?

1 Like