Strategy for dealing with double rows in tt table

I am new to C# and Epicor coding, and trying to write code to print x number of labels depending on a UD field on the PartPlant record. (PrintMethod_c)

I have my foreach loop set up to iterate through ttRcvDtl and it is dutifully spitting out the print method, but it’s doing it twice for each line. I remember reading that tt tables contain double rows (before and after changes) but cannot find the thread or one that gives a quick way to get around that.

To put it simply, what’s the best way to get 3 results for a 3 line receipt instead of 6?

Erp.Tables.PartPlant PartPlant;

foreach(var row in ttRcvDtl)
  {
  string resultPart = row.PartNum;
  
// Get PartPlant record for current ttRcvDtl row  
  PartPlant = (from partpRow in Db.PartPlant where partpRow.Plant == callContextClient.CurrentPlant && partpRow.Company == callContextClient.CurrentCompany && partpRow.PartNum == resultPart select partpRow).FirstOrDefault();
  
// Get Print Method
  string PrintMethod = PartPlant.UDField<System.String>("PrintMethod_c");
  
// Debug MessageBox  
  this.PublishInfoMessage(PartPlant.PartNum + " : " + PrintMethod, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
  
  }

You’re looking for RowMod == “U”. Add that to your query in ttRcvDtl… something like:

foreach (var row in (from r in ttRcvDtl
                     where r.RowMod == "U"
                     select r))
4 Likes
foreach( var row in ttRcvDtl.Where(r=>r.Updated()) )

Jinx.
Both ways work. Different ways to skin a cat.

5 Likes

Darn Cats,

foreach( var row in ttRcvDtl.Where(r=>!r.Unchanged()) )
3 Likes

Another dead cat… :crying_cat_face:
I prefer the following… basically because I know (or not) if there is an entry found. also there is no need for a “foreach” when there is only one row updated.

var myRcvDtl = ttRcvDtl.Where(r=>r.Updated()).FirstOrDefault();
if (myRcvDtl != null){
   //do something here
} else {
  //you can do something else if there was not an updated row
}
2 Likes

Thanks for all the skinned cats! :scream_cat:

Now on to the… fun part… coding the print jobs.

1 Like