表更新事件处理程序 [英] Table Update Event Handler

查看:107
本文介绍了表更新事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调查新代表的能力. AX 2012中的事件订阅模式.

I am investigating the capabilities of the new delegate & event subscription pattern in AX 2012.

此刻,我想检测何时修改了特定字段,例如,当SalesTable.SalesStatus更改为SalesStatus::Invoiced时.

At the moment I am looking to detect when a particular field has been modified, for example when SalesTable.SalesStatus is changed to SalesStatus::Invoiced.

我创建了以下事件后处理程序,并绑定到SalesTable.Update方法;

I have created the following post-event handler and attatched to the SalesTable.Update method;

public static void SalesTable_UpdatePosteventHandler(XppPrePostArgs _args)
{
    Info("Sales Update Event Handler");
}

现在我知道可以从_args中获取SalesTable了,但是如何检测到字段已更改?我真的可以使用before&版本之后,这让我觉得我在这里订阅了错误的事件.

Now I know I can get the SalesTable from the _args, but how can I detect a field has changed? I could really use a before & after version, which makes me think I am subscribing to the wrong event here.

推荐答案

如果update方法未更新该字段,则可以使用pre

If the update method does not update the field, you can use a pre event handler on the update method. If you want to monitor the PriceGroup field on the CustTable table then create a class called CustTableEventHandler containing this method:

public static void preUpdateHandler(XppPrePostArgs _args)
{
    CustTable custTable = _args.getThis();
    if (custTable.PriceGroup != custTable.orig().PriceGroup)
        info(strFmt("Change price group from '%1' to '%2'", custTable.orig().PriceGroup, custTable.PriceGroup));
}

post事件处理程序将不起作用,因为orig()将返回更改后的记录. 同样,如果使用doUpdate更新记录,则不会调用您的处理程序.

A post event handler will not work, as orig() will return the changed record. Also if the the record is updated using doUpdate your handler is not called.

您还可以覆盖CustTable上的aosValidateUpdate,即使使用doUpdate也会被调用.此方法始终在AOS服务器上运行.

You could also override the aosValidateUpdate on CustTable, which is called even if doUpdate is used. This method is always run on the AOS server.

public boolean aosValidateUpdate()
{
    boolean ret = super();
    if (this.PriceGroup != this.orig().PriceGroup)
        info(strFmt("Change price group from '%1' to '%2'", this.orig().PriceGroup, this.PriceGroup));
    return ret;
}

另一个选择是对Application.eventUpdate方法进行全局更改. 在方法的标题中:

Yet another option would be a global change to the Application.eventUpdate method. From the header of the method:

用作内核中的记录时内核调用的回调 如果已设置内核来监视表,则表已更新 记录在该表中.

Serves as a callback that is called by the kernel when a record in a table is updated, provided that the kernel has been set up to monitor records in that table.

开发人员可以设置内核以回调给定的更新 通过将一条记录与所有 字段设置为相关值,其中包括字段logType设置为 事件更新.可以设置内核应该回叫 每当记录更新或特定字段更新时. 与如何调用和设置logUpdate非常相似.通话 此方法的记录将在记录所在的事务中 已更新.

A developer can set up the kernel to call back on updates for a given table by inserting a record into the DatabaseLog kernel table with all fields set to relevant values, which includes the field logType set to EventUpdate. It is possible to set up that the kernel should call back whenever a record is updated or when a specific field is updated.This is very similar to how logUpdate is called and set up. The call of this method will be in the transaction in which the record is updated.

警报规则通知系统使用此方法.我建议不要这样做,除非它是全局更改(例如警报规则).

This method is used by the alert rule notification system. I would recommend against this, unless it is a global change (like alert rules).

可以按照以下说明扩展警报规则.

Alert rules can be extended as described here.

这篇关于表更新事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆