In need of code critique: Part Deux

Similar to what I was trying to accomplish here:

The BAQ call via BPM failed, so I’m now attempting to code it directly in the BPM; that is, to concatenate all the manufacturers into a single column for each part number, then push that into a UD field on the SugPoDtl table when we generate new PO Suggestions.

So here’s the BPM, an In-Transaction Data Directive on the SugPoDtl table:

I regenerated new suggestions several times yesterday, and each time it got hung up and required manually deleting the task from the System Monitor (this is in our Test Environment where it usually takes about 20 minutes). The code editor gave me an OK when I checked the syntax, there are no validation issues, but not even the message boxes popped up while generating suggestions. Where am I going wrong here? Incorrect code, incorrect BPM, etc? Any help is welcome, thanks!

Don’t loop through an open LINQ query, take the linq statement and shove it into a List or an Array first.
.ToList()

I’m not really sure that string.join inside the LINQ statement is supported in LINQ to SQL

2 Likes

Its the for each looping that’s causing the issue.
The in-trans data directive will fire upon each row creation when regenerated.

So in effect what’s happening is:

Row Foreach Loops
1 1
2 3
3 6
4 10

I believe the following code below should point you somewhat in the right direction:

// Grab the row 
var MyRow = (from row in ttSugPoDtl where
row.Company == callContextClient.CurrentCompany
select row ).FirstOrDefault();

if (MyRow != null)
{
	var JobMtl_Row = (from row in Db.JobMtl where
	row.Company == MyRow.Company &&
	row.JobNum == MyRow.JobNum &&
	row.AssemblySeq == MyRow.AssemblySeq &&
	row.MtlSeq == MyRow.JobSeq
	select row ).FirstOrDefault();

	if (JobMtl_Row != null)
	{
		MyRow.MatNotes_c = JobMtl_Row.MatNotes_c;
	}
}

I hope this helps.

1 Like

I tried it like this:

var nameTable = (from p in Db.Part 
      join ap in Db.AprvMfg on p.PartNum equals ap.PartNum
      join m in Db.Manufacturer on ap.MfgNum equals m.MfgNum
      group m by p into g
      select new { PartNum = g.Key, Names = string.Join(",", g.Select(y => y.Name)) }).ToList();
      
      
foreach(var SugPoDtl in ttSugPoDtl)
{

  foreach(var t in(from t in nameTable where t.PartNum.ToString() == SugPoDtl.PartNum.ToString() select t))
  {
    SugPoDtl.AprvMfg_c = t.Names;
  }


}