且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单个字段值不会在缓存更新时更新

更新时间:2023-11-09 22:51:22

SetValueExt 的使用看起来是正确的,前提是 mixQLine 和 scales 都是非空且引用的字段也非空.但是,您应该模拟插入"操作.按钮通过 Document.Insert(kit); 插入您的新 INKitRegister.有时,您需要在插入之前在记录中填写一些值(例如在销售订单中输入 SOType),但在大多数情况下我不需要这样做.如果您的记录存在,通常您会通过以下方式搜索记录:

The use of SetValueExt looks correct, provided mixQLine and scales are both non-null with the referenced fields also non-null. However, you should simulate the "Insert" button via Document.Insert(kit); to insert your new INKitRegister. Sometimes, you need to fill in a few values on the record (like on Sales Order entering SOType) before you insert, but in most cases I haven't needed to do so. If your record exists, typically you would search for the record via:

Document.Current = Document.Search<keyField>(keyValue);

在视图上使用 Insert 方法将确保在图表中触发所有正确事件的情况下创建记录.我***的猜测是这是潜在的问题,尽管在设置某些字段之前您可能需要对缓存进行临时更新.(例如,如果位置与库存 ID 相关联,您可能需要使用库存 ID 更新缓存,以便 DAC 更新选择器并检索适用于该项目的位置.)

Use of the Insert method on the view will ensure the record is created with all the proper events firing in the graph. My best guess is that this is the underlying issue, although you may need an interim update on the cache before setting certain fields. (For instance, if the location is tied to the inventoryID, you likely need to update the cache with the inventoryID so that the DAC updates the selector and retrieves locations applicable to the item.)

未经测试,但我会这样做.

Untested, but this is how I would do it.

KitAssemblyEntry kitGraph = CreateInstance<KitAssemblyEntry>();

INKitRegister kit = new INKitRegister();
// Sometimes need to set initial values here
kit = kitGraph.Document.Insert(kit);

kitGraph.Document.Cache.SetValueExt<INKitRegister.inventoryID>(kit, mixQLine.InventoryID);

//May need to do an interim update on the cache after setting certain fields
kit = kitGraph.Document.Update(kit);

kitGraph.Document.Cache.SetValueExt<INKitRegister.locationID>(kit, scales.LocationID);
kitGraph.Document.Cache.SetValueExt<INKitRegister.uOM>(kit, mixQLine.Uom);
kitGraph.Document.Cache.SetValueExt<INKitRegister.qty>(kit, mixQLine.Qty);

////////////////////////////////
//Alternate way to to set values
kit.InventoryID = mixQLine.InventoryID;

//May need to do an interim update on the cache after setting certain fields
kit = kitGraph.Document.Update(kit);

kit.LocationID = scales.LocationID;
kit.Qty = mixQLine.Qty;
kit.UOM = mixQLine.Uom;
////////////////////////////////

kit = kitGraph.Document.Update(kit);
kitGraph.Actions.PressSave();