I’m trying to update an order’s NeedByDate via Epicor Functions and it’s not working out for me. I am able to open the order and get all of its fields. I am able to change the values, set the RowMod to “U”, but the update doesn’t seem to apply to NeedByDate.
// This approach works with all/most other salesOrderDS.OrderHed[0] fields
salesOrderDS.OrderHed[0].NeedByDate = updatedNeedByDate;
salesOrderDS.OrderHed[0].RowMod = "U";
Then I run the Erp.SalesOrder.ChangeNeedByDate method:
And finally the MasterUpdate method:
Later when I check the NeedByDate, it hasn’t changed. Please note that my code works for updating other fields, just not the NeedByDate.
I had trouble with the OrderHed.NeedByDate too. IIRC there is some built in logic that pushes the date to the lines/releases… might be something like that going on.
If it helps…
I wanted to push updated NeedByDate on the order head to related JobHead.ReqDueDate field. I couldn’t get it to work with pre-processing, nor post-processing. Ended up doing it from a data directive on OrderRel.
Whenever you want to do something like this, do it in the form first with the trace on. Sometimes, changing the field is not enough and you need to call a method for the change to apply. In my case it calls ChangeNeedByDate method when I change need by date - have a look at that.
Thanks for your response.
Yeah I’m already doing that, but apparently it’s also not enough. I’m going to see if TerryR’s approach will work. I might have to apply it to all lines and releases as well.
This was it.
I had to update the OrderRel entries first, then update the OrderHed record, then run Erp.SalesOrder.ChangeNeedByDate on “OrderHed”, then use Erp.SalesOrder.Update BO method (not Master Update).
I didn’t need to change the dates in OrderDtl, they are automatically changed.
I appreciate your help!
For anyone that is interested:
Inputs: orderNum, default lead time
Run Erp.SalesOrder.GetRows with ""OrderNum = '" + orderNum + "'" on the where clause for OrderHed, OrderDtl, OrderRel.
var context = (Erp.ErpContext)Ice.Services.ContextFactory.CreateContext();
var erpContext = new Erp.Internal.Lib.CCredChk(context);
int leadTimeMax = -1;
// find maximum lead time from all lines // we save lead time in PriceLstParts.CommentText
for (int i = 0; i < salesOrderDS.OrderDtl.Count; i++)
{
string partNum = salesOrderDS.OrderDtl[i].PartNum;
using (var txScope = IceContext.CreateDefaultTransactionScope())
{
var partRecord = erpContext.Db.PriceLstParts.Where(r => r.PartNum == partNum).FirstOrDefault();
if (partRecord != null)
{
if (partRecord.CommentText.Length > 0)
{
int temp = Convert.ToInt32(partRecord.CommentText.Split(' ')[0]);
if (temp > leadTimeMax)
{
leadTimeMax = temp; // in days
}
}
else
{
if ((defaultMinLeadTimeWeeks*7) > leadTimeMax)
leadTimeMax = defaultMinLeadTimeWeeks*7; // convert to days
}
}
txScope.Complete();
}
}
int weeks = leadTimeMax == -1 ? defaultMinLeadTimeWeeks : (leadTimeMax + (leadTimeMax%7))/7; // in weeks
updatedNeedByDate = DateTime.Now.AddDays(weeks*7);
for (int i = 0; i < salesOrderDS.OrderRel.Count; i++)
{
salesOrderDS.OrderRel[i].NeedByDate = updatedNeedByDate;
salesOrderDS.OrderRel[i].RowMod = "U";
}
salesOrderDS.OrderHed[0].NeedByDate = updatedNeedByDate;
salesOrderDS.OrderHed[0].RowMod = "U";
// set any output variables here
Erp.SalesOrder.ChangeNeedByDate on cTableName “OrderHed”