C# 单字段值赢得';t在缓存更新时更新

C# 单字段值赢得';t在缓存更新时更新,c#,acumatica,C#,Acumatica,我正在尝试插入INKitRegister项。代码如下: KitAssemblyEntry kitGraph = CreateInstance<KitAssemblyEntry>(); INKitRegister kit = new INKitRegister(); kitGraph.Document.Current = kit; kitGraph.Document.Cache.SetValueExt<INKitRegister.inventoryID>(kit, mixQ

我正在尝试插入
INKitRegister
项。代码如下:

KitAssemblyEntry kitGraph = CreateInstance<KitAssemblyEntry>();
INKitRegister kit = new INKitRegister();
kitGraph.Document.Current = kit;
kitGraph.Document.Cache.SetValueExt<INKitRegister.inventoryID>(kit, mixQLine.InventoryID);
// This line is not working 
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);
kit = kitGraph.Document.Cache.Update(kit) as INKitRegister;
kitGraph.Actions.PressSave();
kitsassemblyEntry kitGraph=CreateInstance();
INKitRegister工具包=新的INKitRegister();
kitGraph.Document.Current=kit;
kitGraph.Document.Cache.SetValueExt(kit,mixQLine.InventoryID);
//这条线坏了
kitGraph.Document.Cache.SetValueExt(工具包,
电子秤(位置ID);
kitGraph.Document.Cache.SetValueExt(kit,mixQLine.Uom);
kitGraph.Document.Cache.SetValueExt(kit,mixQLine.Qty);
kit=kitGraph.Document.Cache.Update(kit)为INKitRegister;
kitGraph.Actions.PressSave();
如果手动配置InventoryItem以指定默认位置,则该项会正确插入所有其他字段,但如果未正确插入,则会引发以下错误:

错误:插入“工具包内拆分”记录时至少引发了一个错误。请检查错误

我做错了什么

“错误”:

2020年9月11日下午2:36:26错误: 错误:插入“工具包内拆分”记录时至少引发了一个错误。请检查错误。 在PX.Data.PXUIFieldAttribute.CommandPreparing(PXCache发送方,PXCommandPreparingEventArgs e) 在PX.Data.PXCache.OnCommandPreparing(字符串名称、对象行、对象值、PXDBOperation操作、类型表、字段描述和描述) 在PX.Data.PXProjectionAttribute.PersistInserted处(PXCache发送器,对象行) 在PX.Data.PXCache.persisted(对象行,布尔旁路拦截器) 在PX.Data.PXCache.Persist处(PXDBOperation操作) 在PX.Data.PXGraph.Persist(类型cacheType,PXDBOperation) 在PX.Data.PXGraph.Persist()处 在PX.Data.PXSave.d_uu2.MoveNext()中 在PX.Data.PXAction.d_u28.MoveNext()中 在PX.Data.PXAction.d_u28.MoveNext()中 在PX.Web.UI.PXBaseDataSource.tryExecutePendingCommand(字符串视图名称、字符串[]排序列、布尔[]后代、对象[]搜索、对象[]参数、PXFilterRow[]过滤器、数据源SelectArguments参数、布尔和closeWindowRequired、Int32和adapterStartRow、Int32和adapterTotalRows) 在PX.Web.UI.PXBaseDataSource.ExecuteSelect(字符串viewName、DataSourceSelectArguments参数、PXDSSelectArguments pxarguments)


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

Document.Current = Document.Search<keyField>(keyValue);
Document.Current=Document.Search(keyValue);
在视图上使用Insert方法将确保创建记录时在图形中触发所有正确的事件。我的最佳猜测是,这是潜在的问题,尽管您可能需要在设置某些字段之前对缓存进行临时更新。(例如,如果位置绑定到inventoryID,则可能需要使用inventoryID更新缓存,以便DAC更新选择器并检索适用于该项的位置。)

未经测试,但我会这样做

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();
kitsassemblyEntry kitGraph=CreateInstance();
INKitRegister工具包=新的INKitRegister();
//有时需要在此处设置初始值
kit=kitGraph.Document.Insert(kit);
kitGraph.Document.Cache.SetValueExt(kit,mixQLine.InventoryID);
//在设置某些字段后,可能需要对缓存进行临时更新
kit=kitGraph.Document.Update(kit);
kitGraph.Document.Cache.SetValueExt(kit,scales.LocationID);
kitGraph.Document.Cache.SetValueExt(kit,mixQLine.Uom);
kitGraph.Document.Cache.SetValueExt(kit,mixQLine.Qty);
////////////////////////////////
//设置值的另一种方法
kit.InventoryID=mixQLine.InventoryID;
//在设置某些字段后,可能需要对缓存进行临时更新
kit=kitGraph.Document.Update(kit);
kit.LocationID=scales.LocationID;
套件数量=混装线数量;
kit.UOM=mixQLine.UOM;
////////////////////////////////
kit=kitGraph.Document.Update(kit);
kitGraph.Actions.PressSave();

我在我的一个项目中使用了下面的代码,并且它按预期工作。此代码可能对您有所帮助

  KitAssemblyEntry kitGraph = PXGraph.CreateInstance<KitAssemblyEntry>();
                INKitRegister objkitregister = PXCache<INKitRegister>.CreateCopy(kitGraph.Document.Insert(new INKitRegister()));
                objkitregister.InventoryID = kitspecifications.KitInventoryID;
                objkitregister.KitRevisionID = SOKitRevisionID;
                objkitregister.Hold = false;
                objkitregister.Qty = Requiredkitqty;
                objkitregister = kitGraph.Document.Update(objkitregister);                   
                kitGraph.Save.Press();
                if (kitGraph.Actions.Contains("Release"))
                {
                    kitGraph.Actions["Release"].Press();
                }
kitsassemblyEntry kitGraph=PXGraph.CreateInstance();
INKitRegister objkitregister=PXCache.CreateCopy(kitGraph.Document.Insert(new-INKitRegister());
objkitregister.InventoryID=kitspecifications.KitInventoryID;
objkitregister.KitRevisionID=SOKitRevisionID;
objkitregister.Hold=false;
objkitregister.Qty=所需套件数量;
objkitregister=kitGraph.Document.Update(objkitregister);
kitGraph.Save.Press();
if(kitGraph.Actions.Contains(“Release”))
{
kitGraph.Actions[“Release”]。按();
}

那么,你已经检查过错误了吗?那你为什么不把它们添加到你的问题中呢?它们不是最有用的,但是请看一看。同意,它们根本没有帮助!谢谢你的详细解释。我还没有见过其他地方使用的insert(以这种方式使用)或search函数,因此这将帮助我解决这个问题。明天我将尝试这些建议。我重新格式化了搜索周围的代码,因为我刚刚注意到它将keyField的括号部分屏蔽为html标记。现在看起来不错。您有
kit=kitGraph.Document.Update(kit)
您不使用
Cache
属性有什么原因吗?
Cache.Update(kit)
是较低级别的功能吗?我确实注意到我必须从
缓存.Update
手动转换结果。这是我最喜欢定制Acumatica的一件事。我将其视为自动执行实际的用户输入,让所有正常的屏幕控件(事件处理程序)完成它们的工作,就像我坐在屏幕的正前方并手动输入一样。