Dan,
I’ve hit these same problems before. So two things:
- @gunny72 is completely correct about needing to do the buffer copy if you want to go with your originally intended approach. I think it is a bit of a nuance to the CustShip.UpdateMaster method that you cannot simply change the row and update like usual. It definitely deletes the pack, quite alarmingly. Here is a snippet I had saved for the last time I ran into this:
var ship = ServiceRenderer.GetService<Erp.Contracts.CustShipSvcContract>(Db);
Erp.Tablesets.CustShipTableset custShipTs = new Erp.Tablesets.CustShipTableset();
custShipTs = ship.GetByID(10272);
var sh = custShipTs.ShipHead.NewRow();
BufferCopy.Copy(custShipTs.ShipHead[0], sh);
custShipTs.ShipHead.Add(sh);
custShipTs.ShipHead[1].LabelComment = DateTime.Now.ToString();
custShipTs.ShipHead[1].RowMod = “U”;
string blah = “”;
bool blah2 = false;
ship.UpdateMaster(ref custShipTs, false, false, false, false, false, false, false, 0, 0, out blah, out blah, out blah, out blah, out blah, out blah, out blah, out blah, out blah, out blah, out blah2, out blah2, out blah, out blah, out blah2, out blah2, out blah2, out blah2);
- On the question about other possible approaches to solving the same requirement, I have taken to writing a Memo on the pack with a subject of ‘Notification Sent’ and including in the body details that will help me trace things out later (like recipients, sent date, etc). So I write the memo when I send the notification and I look for it before I send subsequent notifications. If a resent is required, we can just zap the memo. For example:
Looking for the memo:
var sentNotifications = Db.Memo.Where(m => m.Company == company && m.RelatedToSchemaName == "Erp" && m.RelatedToFile == "ShipHead" && m.Key1 == shipHead.PackNum.ToString() && m.MemoDesc == "Shipment Notification"); if (sentNotifications.Count() == 0) { // Do The Thing }
Writing The Memo:
var memo = ServiceRenderer.GetService<Ice.Contracts.MemoSvcContract>(Db); Ice.Tablesets.MemoTableset memoTs = new Ice.Tablesets.MemoTableset(); memo.GetNewMemo(ref memoTs, "Erp", "ShipHead", shipHead.SysRowID); memoTs.Memo[0].MemoDesc = "Shipment Notification"; memoTs.Memo[0].MemoText = "Shipment notification sent to " + emailToAddress + " " + emailCcAddress + " " + emailBccAddress; memo.Update(ref memoTs);