Edited - was rawtha wordy I have a post-proc method directive whose logic seems to work fine, but , I still haven’t figured out how to invoke the method to change “make direct” on the release. I have managed to stop getting errors, and the code runs logically, but “make direct” remains set regardless.
// SF_MakeSetter 0.0.14
using (var txScope = IceContext.CreateDefaultTransactionScope())
{
string b = ""; // for debugging
if (callContextBpmData.Character01 == "runOnce" && callContextBpmData.Character02 == "reviewOrder" && callContextBpmData.Character03 != "done") // to catch pre-processing and avoid excess runs
{
if (ttOrderHed.Any() && ttOrderDtl.Any() && ttOrderRel.Any()) // to avoid testing a null and getting null runtime exception
{
foreach ( var od in (from d in ttOrderDtl select d).ToList() ) // loop order lines
{
foreach ( var rl in (from r in ttOrderRel where r.OrderLine == od.OrderLine select r).ToList() ) // loop releases
{
if ( (from p in Db.PartPlant where p.Company == rl.Company && p.PartNum == rl.PartNum && p.Plant == rl.Plant && p.SourceType.Equals("M") select p).Any() ) // test for manufactured in the target plant
{
if ( (from w in Db.PartWhse where w.Company == rl.Company && w.PartNum == rl.PartNum && w.WarehouseCode.Contains(rl.Plant) && w.WarehouseCode.Contains("001") && (rl.SellingReqQty < ( w.OnHandQty - ( w.SalesAllocatedQty + w.SalesDemandQty + w.ReservedQty + w.AllocatedQty) ) ) select w ).Any() ) // check stock
{
try
{
using (var so = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(this.Db) ) // get the service instance
{
int oNum = od.OrderNum;
int oRel = rl.OrderRelNum;
var soTs = so.GetByID(oNum); // load my tableset
// almost no idea what's going on after this point!
for (int i = 0; i < soTs.OrderRel.Count; i++) // loop through and ...
{
if (soTs.OrderRel[i].OrderLine == rl.OrderLine) // ... correlate my releases and orderlines
{
soTs.OrderRel[i].RowMod = "U"; // does this set the release to be updated?
so.ChangeMake(false, ref soTs); // is this in the right context?
}
}
callContextBpmData.Character03 = "done"; // added to ensure code doesn't run again if update is called multiple times for some reason
this.dsHolder.Attach(soTs); // from the Epicor C# guide to replace the dataset; not sure if I understand it correctly
so.Update(ref soTs); // update only the context of the tableset?
// end "no idea... section"
} // end using Sales Order svc
} // end try
catch (Exception e )
{
b = b + " error " + e ;
Ice.Diagnostics.Log.WriteEntry(b);
} // end catch
} // end check for stock
} // end check if part manufactured at release plant
} // end loop through releases
} // end loop thorugh order lines
} // end if Order, Dtl and Rel exist
} // end if review & run once check
txScope.Complete();
Ice.Diagnostics.Log.WriteEntry("18 - completed txScope " + callContextBpmData.Character03);
} // end txScope
I’m gonna really owe this forum after this… but any insights would be appreciated!