So when you call Sales.Update() you want to look through all the OrderDetails in the Order and display a message box for each line that has this problem?
Is this what you need? I did a few tweaks, but added an initialize line at the beginning of the loop:
foreach (var od in ttOrderDtl) {
//loop through each partwhse record for the part being ordered to calculate demand and on hand qtys
totalDemand =
totalonhand =
pwcount = 0; //@@@@THIS IS THE NEW LINE!!!@@@@
foreach (var pw in (from PartWhse_Row in Db.PartWhse where (string.Compare (PartWhse_Row.Company, od.Company, true) == 0 &&
string.Compare (PartWhse_Row.PartNum, od.PartNum, true) == 0) select PartWhse_Row)) {
//calc total demand and onhand for all partwhse rows
totaldemand += pw.DemandQty;
totalonhand += pw.OnHandQty;
//count partwhse rows found
pwcount += 1;
}
//only run if partwhse record found to exclude potf's
if (pwcount > 0) {
//exclude this line qty from calculation as epicor states they do in field notes
if (totaldemand != 0) {
totaldemand = totaldemand - od.OrderQty;
}
//calc total available qty
totalavail = totalonhand - totaldemand;
//enable message below to troubleshoot all calculations
//this.PublishInfoMessage("Total on hand: " + Convert.ToString(totalonhand) + "\rTotal demand: " + Convert.ToString(totaldemand) + "\r\rAvailable: " + Convert.ToString(totalavail) + "\rThis line: " + Convert.ToString(od.OrderQty), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
if (totalavail < od.OrderQty) {
this.PublishInfoMessage ("Order is for greater quantity than is currently available. Please review. \r\rAvailable: " + Convert.ToString (Math.Round (totalavail, 2)) + "\rThis Line: " + Convert.ToString (Math.Round (od.OrderQty, 2)) + "\r\rEpicor BPM\rMethod SalesOrder.Update Pre and Post\rSeq 10", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
}
}
}
i will try it and let you know
FYI… this c# code could be reduced considerably…
- the foreach that does the math could instead do a query that returns the three values as summarized values, eliminating the “foreach”
- the second big if statement (if (pwcount)) with all the internals could be tweaked to be one line of code.
I am currently on a rampage that involves optimizing some badly written BPMs that loop through data… While it seems that 500 milliseconds is not long for one line item (1/2 second)… when you have Epicor Commerce Connect drop in 30 line items into an order all at once, the user has to wait 15 seconds to get a response… we optimized the BPM so that the total wait time is back down to 1/4 second for all 30.
I just fixed one yesterday (that I wrote… shame on me) that was taking 18 seconds when a certain condition happened. Obviously bad query… tweaked, and now is about 2ms.
Piggy backing off of Tim,
I tweaked a customization to use a dynamic query adapter to run a simple BAQ I designed to do a check on the data returned. I initially was doing Part.GetByID. This increased the performance of that method by 97.3%. I simply did not need all the data the getByID method was returning.
Always keep your code simple, elegant, tight, and ensure you test performance on large amounts of data. Oh, and COMMENT your code too! I see you did in this example tho, good!!
Ahhhhh, I thought it was his accent showing through… Oops. Haha.