Hi,
I’m trying to figure out the best approach for a BPM. Want to trigger on ShipHed.ReadyToInvoice = true either from CustShip.UpdateMaster method directive or a data directive on the ShipHead table.
I’ve looked at so many different examples I’m not sure which is the most efficient route at this point. And I’m really new to trying to code anything in C#. I’m trying to look at the Shipment and select the unique order numbers on the shipment from the Ship Detail lines. Then I need to loop through each of these order numbers to see if they already exists on another pack. Ultimate goal is the see how many of the order numbers on the pack don’t already exist on another pack.
There is a field called OrderHed.TotalShipped that I thought I could reference, but it seems to be 0 for most Orders that have shipped. It’s only populated a few sporadic times, so not sure what triggers it to be populated?
I’m very new to C# so any help or relevant examples is appreciated. General outline of what I think I should do:
var PackNum = ttShipHed.PackNum;
var iterator = 0;
Need to apply a charge once per order. Orders may be split across multiple shipments and charges available through Manifest are only available on a per shipment basis.
The iterator will tell me how many of the orders on the pack are first shipments for each of those orders.
Thanks. Here’s some half-written code mixed with comments to show how I’d probably try it. I’m sure there are many other ways it can work too.
int packNum = ttShipHed.PackNum;
int iterator = 0;
var orderNumsList = //loop through ttShipDtl and build unique orderNums into a list
foreach(var uniqueOrder in orderNumsList)
{
bool shipmentExistsForOrder = Db.ShipDtl.Any(sd => sd.PackNum != packNum && sd.OrderNum = uniqueOrder.order); // that “order” would be a variable name used in the construction of orderNumsList
if (!shipmentExistsForOrder)
{
// increment the iterator
}
So here’s what we have so far. It validates without issue, but the fields aren’t getting set. Anything look off in this code?
var ttShipH = (from ttShipHead_Row in ttShipHead
where ttShipHead_Row.Company == Session.CompanyID
select ttShipHead_Row).FirstOrDefault();
int packNum = ttShipH.PackNum;
int iterator = 0;
int iChargeAmt = 25;
var orderNumsList = new ArrayList(); //loop through ttShipDtl and build unique orderNums into a list
if(ttShipH != null)
{
foreach(var det in (from ShipDtl_Row in Db.ShipDtl
where ShipDtl_Row.Company == ttShipH.Company
&& ShipDtl_Row.PackNum == ttShipH.PackNum
select ShipDtl_Row).ToList())
{
if (det != null)
{
if (!orderNumsList.Contains(det.OrderNum))
{ // Add to the list if not already there
orderNumsList.Add(det.OrderNum);
}
}
}