BPM how to loop through rows in tt table?

I’ve been trying to look up some example that would help my figure this out and I can’t figure out what I need so I am going to ask you guys.

How do I loop through rows in a BPM custom code block to build up a string? I’m trying to do it like I did for writing out CSV’s, but that was using a grid, so something doesn’t translate like I was hoping it would. This is the start of what I have, but I get an error.

    foreach(var row in ttShipDtl.Rows)
        { 
        string peice = string.Format("{0}{1}{2}{3}", row.ttShipDtl.OrderNum, row.ttShipDtl.OurShippedQty, row.ttShipDtl.PartNum, row.Email.LineDesc);

        mystring += mystring + peice;
        }

CS1061 'ShipDtlTable' does not contain a definition for 'Table' and no extension method 'Table' accepting a first argument of type 'ShipDtlTable' could be found (are you missing a using directive or an assembly reference?)

So what am I doing wrong?

you can do it two ways…

  1. foreach ( var row in ttShipDtl)
    {
    string peice = $"{row.OrderNum}{ row.OurShippedQty}…");
    mystring += peice;
    }

  2. foreach (var row in (from shipDtlRow in ttShipDtl select shipDtlRow.))
    {
    string peice = $"{row.OrderNum}{ row.OurShippedQty}…");
    mystring += peice;
    }

1 Like

I was trying to do too much! thanks. Looking at your examples, I realized that I didn’t need the ttShipDtl in the “row.ttShipDtl.OrderNum” pieces. I took those out and now I get no errors. Looks like this.

foreach(var row in ttShipDtl)
    { 
    string peice = string.Format("{0}{1}{2}{3}", row.OrderNum, row.OurShippedQty, row.PartNum, row.LineDesc);
    mystring += mystring + peice;
    }

Whether is works or not, we’ll see…

1 Like

You can’t use interpolated strings in a BPM (yet) :frowning:

Jose, What do you mean about the interpolated string usage in a BPM? I’ve been using code like this and it has been working fine. Did I misunderstand something?

mystring += String.Format("{0} {1}{2} {3}{4}   {5}{6}{7} {8}", orderNum.PadRight(9),counter+partNum.PadRight(20),bin.PadRight(8),partDesc.PadRight(32),qty.PadLeft(4),weight.PadRight(6,'0'),bin2.PadRight(15), country.PadRight(32), uom.PadRight(3));

Nathan

@Nathan_Woolen that works, I was referring specifically to the $“{var}” syntax referenced above by suteraj20. That’s C#6 and not yet available in most versions of E10 :frowning:

In later versions instead of doing what you typed

mystring += string.Format("My Formatted String: {0} {1}", varHello,varWorld);

You can do this

mystring += $"My Formatted String: {varHello} {varWorld}";

and “interpolate” the variables directly in the string. Which is uber awesome

@josecgomez I understand now. Thanks for the clarification.

Nathan

1 Like

Didn’t realize that it was specific to 10.1.600??

1 Like

So this is the final (kind of) result. I’ll be putting this into a simple auto e-mail and probably some other information.

Here’s the code in the code block

string mystring = "Order Num, Qty, Part number, Description"+ Environment.NewLine;

foreach(var row in ttShipDtl)
    { 
    string peice = string.Format("{0}      {1}  {2}   {3}", row.OrderNum, row.OurShippedQty, row.PartNum, row.LineDesc);
    mystring += peice + Environment.NewLine;
    }
 this.OrderLineInfo = mystring;

You can shortcut the Enviornment.NewLine to “\n” if you would like…

string mystring = “Order Num, Qty, Part number, Description\n”;

mystring += peice + “\n”;

1 Like

I believe you should be using “\r\n” if you chose to not use Environment.NewLine