简体   繁体   English

Dynamics Ax:任何记录更改时发出警报

[英]Dynamics Ax: Alert when any record changes

I want to send an alert in Ax, when any field in the vendor table changes (and on create/delete of a record). 当供应商表中的任何字段发生更改时(以及在创建/删除记录时),我都希望在Ax中发送警报。

In the alert, I would like to include the previous and current value. 在警报中,我想包括先前值和当前值。

But, it appears that you can't set alerts for when any field in a table changes, but need to set one up for EVERY FIELD?! 但是,您似乎无法为表中的任何字段更改设置警报,而是需要为每个字段设置一个警报? I hope I am mistaken. 我希望我弄错了。

And how can I send this notification to a group of people 以及如何将此通知发送给一群人

I have created a new class with a static method that I can easily call from any .update() method to alert me when a record changes, and what changed in the record. 我用静态方法创建了一个新类,可以轻松地从任何.update()方法中调用.update()以在记录更改以及记录中发生更改时提醒我。

It uses the built in email templates of Ax as well. 它还使用Ax的内置电子邮件模板。

static void CompareAndEmail(str emailTemplateName, str nameField, str recipient, Common original, Common modified)
{
    UserInfo    userInfo;
    Map         emailParameterMap = new Map(Types::String, Types::String);
    str         changes;
    int         i, fieldId;    
    DictTable   dictTable = new DictTable(original.TableId);
    DictField   dictField;
;

    for (i=1; i<=dictTable.fieldCnt(); i++)
    {
        fieldId = dictTable.fieldCnt2Id(i);
        dictField = dictTable.fieldObject(fieldId);

        if (dictField.isSystem())
            continue;

        if (original.(fieldId) != modified.(fieldId))
        {
            changes += strfmt("%1: %2 -> %3 \n\r",
                dictField.name(),
                original.(fieldId),
                modified.(fieldId)
            );
        }
    }

    //Send Notification Email
    select Name from UserInfo where userInfo.id == curUserId();
    emailParameterMap.insert("modifiedBy", userInfo.Name);
    emailParameterMap.insert("tableName", dictTable.name());
    emailParameterMap.insert("recordName", original.(dictTable.fieldName2Id(nameField)));
    emailParameterMap.insert("recordChanges", changes);

    SysEmailTable::sendMail(emailTemplateName, "en-us", recipient, emailParameterMap);
}

Then in the .update() method I just add this one line 然后在.update()方法中,我只添加这一行

//Compare and email differences
RecordChangeNotification::CompareAndEmail(
    "RecChange",            //Template to use
    "Name",                 //Name field of the record (MUST BE VALID)
    "user@domain.com", //Recipient email
    this_Orig,              //Original record
    this                    //Modified record
);

The only things I want to improve upon are: 我唯一需要改进的是:

  • moving the template name and recipient into a table, for easier maintenance 将模板名称和收件人移动到表中,以便于维护
  • better formatting for the change list, I don't know how to template that (see: here ) 更改列表的格式更好,但我不知道该如何对其模板化(请参阅: 此处

As you have observed the alert system is not designed for "any" field changes, only specific field changes. 如您所见,警报系统不是为“任何”字段更改而设计的,而仅是针对特定字段的更改而设计的。

This is a bogus request anyway as it would generate many alarts. 无论如何,这是一个虚假的请求,因为它会产生许多警报。 The right thing to do is to enable database logging of the VendTable table, then send a daily report (in batch) to those interested. 正确的做法是启用VendTable表的数据库日志记录,然后将每日报告(批量)发送给感兴趣的人。

This is done in Administration\\Setup\\Database logging. 这是在Administration \\ Setup \\ Database日志记录中完成的。 There is a report in Administration\\Reports. Administration \\ Reports中有一个报告。 You will need to know the table number to select the table. 您将需要知道表号才能选择表。 This solution requires a "Database logging" license key. 此解决方案需要“数据库记录”许可证密钥。

If you really need this feature, then you can create a class that sends a message/email with the footprint of the old record vs the new record. 如果确实需要此功能,则可以创建一个类,该类使用旧记录和新记录的足迹发送消息/电子邮件。 Then simply add some code in the table method "write"/"update"/"save" to make sure you class is run whenever vendtable gets edited. 然后只需在表方法“ write” /“ update” /“ save”中添加一些代码,以确保只要编辑了vendtable便运行您的类。 But I have to agree with Jan. This will generate a lot of alerts. 但我必须同意Jan。这将产生很多警报。 I'd spend some energy checking if the modifications done in vendtable are according to the business needs, and prohibit illegal modifications. 如果在vendtable中进行的修改是否符合业务需求,我会花一些精力进行检查,并禁止非法修改。 That includes making sure only the right people have enough access. 这包括确保只有合适的人才有足够的机会。

Good luck! 祝好运!

I do agree with suggestion of Skaue.you just write and class to send the mail of changes in vend table. 我确实同意Skaue的建议。您只需编写类并发送更改表中的更改邮件即可。 and execute this class on update method of vendtable. 并在vendtable的update方法上执行此类。

thanks and Regards, Deepak Kumar 感谢和问候,Deepak Kumar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM