ldavid1113
(Lynn David)
September 18, 2018, 1:18pm
1
Trying to sum 2 decimal fields in Linq in BPM and receive message "decimal does not contain a definition for ‘Sum’. Searched web and codes found did not work due to using foreach on PartWhse table. Trying to sum (PartWhse.OnHandQty - PartWhse.DemandQty).
Thank you
THulbert
(Tom Hulbert)
September 18, 2018, 1:42pm
2
I’ve always wanted to say this: Can you please post your code?
3 Likes
A.Baeisa
(Al)
September 18, 2018, 2:32pm
3
could you post the code ?
1 Like
ldavid1113
(Lynn David)
September 18, 2018, 4:01pm
4
foreach (var PartMtl_iterator in (from PartMtl_Row in Db.PartMtl
where PartMtl_Row.Company == CompanyID
&& PartMtl_Row.PartNum == ttOrderDtl_xRow.PartNum
select PartMtl_Row))
{
var PartMtlRow = PartMtl_iterator;
this.PublishInfoMessage("PartMtl.PartNum: " + PartMtlRow.PartNum.ToString() + " PartMtl.MtlPartNum: " + PartMtlRow.MtlPartNum.ToString(), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "OrderDtl", "Update");
foreach (var PartWhse_iterator in (from PartWhse_Row in Db.PartWhse
where PartWhse_Row.Company == CompanyID
&& PartWhse_Row.PartNum == PartMtlRow.MtlPartNum
select PartWhse_Row))
{
var PartWhseRow = PartWhse_iterator;
callContextBpmData.Number01 = PartWhseRow.OnHandQty.Sum();
callContextBpmData.Number02 = PartWhseRow.DemandQty.Sum();
Math.Min(PartWhseRow.OnHandQty, PartWhseRow.DemandQty);
this.PublishInfoMessage("PartWhse.OnhandQty: " + PartWhseRow.OnHandQty.ToString() + " PartWhse.DemandQty: " + PartWhseRow.DemandQty.ToString(), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "OrderDtl", "Update2");
}
}
You’re attempting to sum a decimal, not a collection so it doesn’t know what do to do with it.
1 Like
Chris_Conn
(Chris Conn)
September 18, 2018, 4:14pm
6
//at top
decimal OnHandQtySum = 0;
decimal DemandQtySum = 0;
foreach....
{
var PartWhseRow = PartWhse_iterator;
OnHandQtySum += PartWhseRow.OnHandQty;
DemandQtySum += PartWhseRow.DemandQty;
}
callContextBpmData.Number01 = OnHandQtySum;
callContextBpmData.Number02 = DemandQtySum;
1 Like
ldavid1113
(Lynn David)
September 18, 2018, 6:05pm
7
Thank you. I need to modify code because not exactly getting the results I was expecting.
A.Baeisa
(Al)
September 19, 2018, 12:43pm
8
Hi Lynn,
i think that your issue is with the Sum() function, i have replaced it with what @Chris_Conn suggested and it worked for me, however i do not think that you are targeting the right method, i have created min at “ChangePartNumMaster” method
and Post BPM withim SalesOrder BO, this way it will be triggered at each PartNum Change in OrderDtl, this is my code:
callContextBpmData.Number01=0.0m;
callContextBpmData.Number02=0.0m;
var ttOrderDtl_xRow = (from ttOrderDtl_Row in ttOrderDtl
where ttOrderDtl_Row.Company == Session.CompanyID
&& (ttOrderDtl_Row.Updated()||ttOrderDtl_Row.Added())
select ttOrderDtl_Row).FirstOrDefault();
if (ttOrderDtl_xRow != null)
{
foreach (var PartMtl_iterator in (from PartMtl_Row in Db.PartMtl
where PartMtl_Row.Company == ttOrderDtl_xRow.Company
&& PartMtl_Row.PartNum == ttOrderDtl_xRow.PartNum
&& PartMtl_Row.RevisionNum == ttOrderDtl_xRow.RevisionNum
select PartMtl_Row).ToList())
if (PartMtl_iterator != null)
{
var PartMtlRow = PartMtl_iterator;
PublishInfoMessage("PartMtl.PartNum: " + PartMtlRow.PartNum.ToString() + " PartMtl.MtlPartNum: " + PartMtlRow.MtlPartNum.ToString(), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, “SalesOrder”, “ChangePartNumMaster”);
foreach (var PartWhse_iterator in (from PartWhse_Row in Db.PartWhse
where PartWhse_Row.Company == CompanyID
&& PartWhse_Row.PartNum == PartMtlRow.MtlPartNum
select PartWhse_Row))
{
var PartWhseRow = PartWhse_iterator;
callContextBpmData.Number01 = callContextBpmData.Number01+PartWhseRow.OnHandQty;
callContextBpmData.Number02 = callContextBpmData.Number02+PartWhseRow.DemandQty;
Math.Min(PartWhseRow.OnHandQty, PartWhseRow.DemandQty);
PublishInfoMessage("PartWhse.OnhandQty: " + callContextBpmData.Number01 + " PartWhse.DemandQty: " + callContextBpmData.Number02, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "SalesOrder", "ChangePartNumMaster");
}
}
}
2 Likes
ldavid1113
(Lynn David)
September 19, 2018, 5:25pm
9
Thank you very much. That was very kind of you and much appreciated. The problem is the On Hand Quantity and Demand Quantity is not calculating correctly.
ldavid1113
(Lynn David)
September 20, 2018, 3:07pm
10
I have the amounts per warehouse calculating correctly with this query. But I cannot seem to find code to get the minimum value for (PartWhseRow.OnHandQty - PartWhseRow.DemandQty).
foreach (var PartWhse_iterator in (from PartWhse_Row in Db.PartWhse
where PartWhse_Row.Company == CompanyID
&& PartWhse_Row.PartNum == PartMtlRow.MtlPartNum
select PartWhse_Row).ToList())
{
var PartWhseRow = PartWhse_iterator;
callContextBpmData.Number01 = (PartWhseRow.OnHandQty - PartWhseRow.DemandQty);
Chris_Conn
(Chris Conn)
September 20, 2018, 3:46pm
11
Heres a rudimentary way you could approach it:
//global
decimal min = 9999999m;
foreach()
{
decimal dif = (PartWhseRow.OnHandQty - PartWhseRow.DemandQty);
callContextBpmData.Number01 += dif;
if(dif < min) min = dif;
}
You also just store the entire row/record of the min so you could access any field from it afterwards
ldavid1113
(Lynn David)
September 20, 2018, 6:10pm
12
Not to sound naïve, but do I store it to another callContextBpmData field?
Chris_Conn
(Chris Conn)
September 20, 2018, 6:25pm
13
I guess it just depends on what you want to do with it. You certainly can store it in another callcontext field if you need it passed out of the BPM.