通过事件处理程序从Acumatica图中添加DB中的值
我想为我的dacextension之一添加DB中的价值。
protected void ScanHeader_Barcode_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
ScanHeader row = (ScanHeader)e.Row;
HeaderExt headerExt = row.GetExtension<HeaderExt>();
PickPackShip.Host graph = PXGraph.CreateInstance<PickPackShip.Host>();
SOShipment shipment = (from p in graph.Select<SOShipment>()
where
p.ShipmentNbr == row.Barcode
select p).FirstOrDefault();
if (shipment != null)
{
SOShipmentExt shipmentExt = shipment.GetExtension<SOShipmentExt>();
cache.SetValueExt<SOShipmentExt.myField>(shipment, headerExt.MyField);
}
}
我正在尝试这样的尝试,但这不起作用。我的图形没有直接与Soshipment相关。 我的图是pickpackship.host
I want to add value in DB for one of my DACExtension.
protected void ScanHeader_Barcode_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
ScanHeader row = (ScanHeader)e.Row;
HeaderExt headerExt = row.GetExtension<HeaderExt>();
PickPackShip.Host graph = PXGraph.CreateInstance<PickPackShip.Host>();
SOShipment shipment = (from p in graph.Select<SOShipment>()
where
p.ShipmentNbr == row.Barcode
select p).FirstOrDefault();
if (shipment != null)
{
SOShipmentExt shipmentExt = shipment.GetExtension<SOShipmentExt>();
cache.SetValueExt<SOShipmentExt.myField>(shipment, headerExt.MyField);
}
}
I am trying like this but this is not working. My graph is not directly linked with SOShipment.
My graph is PickPackShip.Host
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要更新同一缓存的另一个字段,则更新字段时仅在字段更新事件中使用该字段。由于您正在在另一个记录上设置一个值,因此仅设置该值是不够的。您还必须更新该记录的缓存。
这假设您的图表中有一个缓存,并且当您保存时将持续存在。
我发现有趣的是,您正在创建图形的实例来选择您的记录,然后不使用该图来更新该值。如果您只是初始化了同一图的另一个副本,则可以通过 base 简化,如果您在自己的自定义图中添加了另一个图形或 this 。假设您要设置的自定义字段上没有任何事件处理程序,我只会在图形扩展中添加一个视图,然后将其直接进行更新。如果您想变得超级适当,则可能需要使用Soshipmentry图,这是Soshipment的主要图表,以便将来添加事件处理程序的任何添加。然后确保在该图中找到您的记录,然后使用该图来更新/保存更改。一切都取决于您的目标,但绝对值得考虑。
如果您具有正确的图形,并且想通过pickpackship.host图表进行更新,则在代码中称为图形,然后用 cache graph.caches [typeof(soshipment)] 和然后,请确保 graph.save.press();
如果要使用Soshipmentry Graph,则更新的核心可能会如下:
Updating the field as you are only works that way on a field updated event if you are updating another field of the same cache. Since you are setting a value on another record, just setting the value is not enough. You also must Update the cache for that record.
This assumes that SOShipment has a cache in your graph and will be persisted when you Save.Press().
I find it interesting that you are creating an instance of a graph to select your record and then not using that graph to update the value. If you are just initializing another copy of the same graph, then you could simplify by using Base if you are extending another graph or this if you are in your own custom graph. Assuming you don't have any event handlers on your custom field that you want to set, I'd just add a view for SOShipment in your graph extension and update it directly. If you want to be super proper, you likely would want to use the SOShipmentEntry graph instead, which the primary graph for SOShipment so that any future addition of event handlers would be picked up. Then be sure to find your record in that graph and then use THAT graph to update/save your changes. All depends on your objectives, but definitely worth thinking about.
If you have the right graph and want to update via the PickPackShip.Host graph called graph in your code, then replace cache with graph.Caches[typeof(SOShipment)] and then be sure to graph.Save.Press();
If you want to use the SOShipmentEntry graph instead, the core of the update might look like this: