1

I want to send an alert in Ax, when any field in the vendor table changes (and on create/delete of a record).

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

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
CaffGeek
  • 21,856
  • 17
  • 100
  • 184

4 Answers4

3

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.

It uses the built in email templates of Ax as well.

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

//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)
Community
  • 1
  • 1
CaffGeek
  • 21,856
  • 17
  • 100
  • 184
2

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.

This is done in Administration\Setup\Database logging. There is a report in Administration\Reports. You will need to know the table number to select the table. This solution requires a "Database logging" license key.

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
  • It's not a "bogus request". When changes are saved, we want to send a singular email with the changed fields and their prior values. Sending a daily batch is too late. It's 2010, we shouldn't be working with nightly batches to deliver information. Vendors are infrequently updated, but if they are modified, our executives want to know IMMEDIATELY. – CaffGeek Nov 30 '10 at 16:47
  • Ok, then run the report every minute or hour whatever suits your executives. – Jan B. Kjeldsen Dec 01 '10 at 19:37
  • The solution I provided is quite simple and delivers. You cannot expect AX to provide any function imaginable out the box. Your executives request is not a common one! – Jan B. Kjeldsen Dec 02 '10 at 18:39
  • How is knowing when important records are changed not a common request? Notifications are already setup at the field level...why wouldn't you write the software to handle them at the record level while you're at it? Seems half baked. – CaffGeek Jan 19 '11 at 14:45
1

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. But I have to agree with Jan. This will generate a lot of alerts. I'd spend some energy checking if the modifications done in vendtable are according to the business needs, and prohibit illegal modifications. That includes making sure only the right people have enough access.

Good luck!

Skaue
  • 763
  • 4
  • 13
  • making sure the right people have access is done. There are only 2 people with edit access, but that doesn't mean they are the only ones that need to know when changes happen. And I also don't understand how this will generate "a lot of alerts". Vendor records are updated on average a total of 3 times per day (we ran some stats on the change history in our old software). That's 3 emails per day. One for each vendor that was changed, when it was changed. Hardly "a lot of alerts". – CaffGeek Dec 01 '10 at 15:07
1

I do agree with suggestion of Skaue.you just write and class to send the mail of changes in vend table. and execute this class on update method of vendtable.

thanks and Regards, Deepak Kumar

Deepak Kalra
  • 101
  • 1
  • 1