Hello!!
I have this code in a Standard data directive over OrderDtl. It creates new lines when line is created.
The problem is that is not updating the OrderHed totals. Please help!!!
OrderHed summary has all totals as 0
My OrderDtl look good.
debugString = "";
try
{
foreach (var row in ttOrderDtl)
{
debugString += $"\n--- Processing Order {row.OrderNum} ---\n";
if (string.IsNullOrWhiteSpace(row.CPQ_JSON_c))
{
continue;
}
using (JsonDocument doc = JsonDocument.Parse(row.CPQ_JSON_c))
{
var root = doc.RootElement;
JsonElement extraLines;
if (!root.TryGetProperty("extraLines", out extraLines) ||
extraLines.ValueKind != JsonValueKind.Array)
{
continue;
}
foreach (var extraLine in extraLines.EnumerateArray())
{
try
{
bool lContinue = false;
string cResponseMsg, cCreditShipAction, cDisplayMsg, cCompliantMsg, cResponseMsgOrdRel;
string cAgingMessage, cUserMessage, cResponseMsgQuotes, cReleaseResponseMsg;
string deleteComponentMessage, questionString, warningMessage, subPartMessage, explodeBOMerrMessage, msgType, cWarningMessage;
bool multiplePatch, promptToExplodeBOM, multiSubsAvail, runOutQtyAvail;
string sqMsg1, sqMsg2, sqMsg3, sqMsg4;
string partNum = extraLine.GetProperty("partNumber").GetString();
decimal qty = extraLine.GetProperty("quantity").GetDecimal();
decimal price = extraLine.GetProperty("price").GetDecimal();
string lineType = extraLine.GetProperty("lineType").GetString();
bool isZeroLine = lineType == "ZeroLine";
if (isZeroLine) price = 0;
this.CallService<Erp.Contracts.SalesOrderSvcContract>(soSvc =>
{
var ds = soSvc.GetByID(row.OrderNum);
var custNum = ds.OrderHed[0].CustNum;
var existingLine = ds.OrderDtl
.FirstOrDefault(x => x.PartNum == partNum);
if (existingLine != null)
{
existingLine.OrderQty += qty;
existingLine.UnitPrice = price;
existingLine.DocUnitPrice = price;
existingLine.LockPrice = isZeroLine;
existingLine.RowMod = "U";
//soSvc.ChangeSellingQuantity(ref ds, true, existingLine.OrderQty, out sqMsg1);
soSvc.ChangeSellingQtyMaster(
ref ds,
existingLine.OrderQty,
false, false, true, true, true, true,
existingLine.PartNum,
existingLine.WarehouseCode, "", "",
0,
existingLine.DimCode,
existingLine.DimConvFactor,
out sqMsg1,
out sqMsg2,
out sqMsg3,
out sqMsg4);
}
else
{
soSvc.GetNewOrderDtl(ref ds, row.OrderNum);
var newLine = ds.OrderDtl
.LastOrDefault(x => x.RowMod == "A")
?? ds.OrderDtl.OrderByDescending(x => x.OrderLine).First();
newLine.PartNum = partNum;
bool substitutePartExist = false;
bool isPhantom = false;
string tempPartNum = partNum;
string uomCode = "";
soSvc.ChangePartNumMaster(
ref tempPartNum,
ref substitutePartExist,
ref isPhantom,
ref uomCode,
newLine.SysRowID,
newLine.RowMod,
false, // salesKitView
false, // removeKitComponents
true, // suppressUserPrompts
true,
true,
true,
true,
out deleteComponentMessage,
out questionString,
out warningMessage,
out multiplePatch,
out promptToExplodeBOM,
out questionString,
out subPartMessage,
out explodeBOMerrMessage,
out msgType,
out multiSubsAvail,
out runOutQtyAvail,
out cWarningMessage,
ref ds
);
newLine = ds.OrderDtl
.LastOrDefault(x => x.RowMod == "A")
?? ds.OrderDtl.OrderByDescending(x => x.OrderLine).First();
newLine.OrderQty = qty;
newLine.UnitPrice = price;
newLine.DocUnitPrice = price;
newLine.LockPrice = isZeroLine;
newLine.RowMod = "A";
//soSvc.ChangeSellingQuantity(ref ds, true, existingLine.OrderQty, out sqMsg1);
soSvc.ChangeSellingQtyMaster(
ref ds,
newLine.OrderQty,
false, false, true, true, true, true,
newLine.PartNum,
newLine.WarehouseCode, "", "",
0,
newLine.DimCode,
newLine.DimConvFactor,
out sqMsg1,
out sqMsg2,
out sqMsg3,
out sqMsg4);
existingLine = newLine;
}
soSvc.Update(ref ds);
/*
ds.OrderDtl.RemoveAll(x => x.SysRowID != existingLine.SysRowID);
soSvc.MasterUpdate(
true, // lCheckForOrderChangedMsg
true, // lcheckForResponse
"OrderDtl", // cTableName
custNum, // iCustNum
row.OrderNum, // iOrderNum
true, // lweLicensed
out lContinue,
out cResponseMsg,
out cCreditShipAction,
out cDisplayMsg,
out cCompliantMsg,
out cResponseMsgOrdRel,
out cAgingMessage,
out cUserMessage,
out cResponseMsgQuotes,
out cReleaseResponseMsg,
ref ds
);
*/
});
}
catch (Exception innerEx)
{
debugString += $" ERROR: {innerEx.Message}\n";
}
}
}
}
throw new Exception("Adding extra lines finished");
}
catch (Exception ex)
{
debugString += "\n=== FATAL ERROR ===\n" + ex.Message + "\n" + ex.StackTrace;
throw new Ice.BLException(debugString);
}

