Dynamics Ax Alerting multiple users (By email)

First things first… the original post that I found about this topic can be found here : http://dynamic-ax.co.uk/DynamicsAXAlertsToMultipleUsers.aspx

But since the link to the xpo was broken , I created this post to put this online and make some minor changes. (Don’t mind some best practices stuff like labels, security keys, … because you’ll probably create your own to use )

First we create a table and form to contain the recipient list.

Event Rule Recipient List

 

Then an adjustment is needed in the EventCreateRule class, method Run. Here the event rule will be updated so we need to maintain the link between the EventRuleId and the recipients table.

public void run()
{
    #OCCRetryCount
    EventRule           eventRuleDB;
 
    // KeSae : 21/04/2010 : Alerting multiple mail recipients
    EventRuleId        oldRuleId;
    ;
 
    try
    {
        ttsbegin;
 
        select firstonly eventRuleTmp;
 
        eventRuleDB.data(eventRuleTmp);
        eventRuleDB.setDeleteRefRecId(callerRecord);
 
        // KeSae : 21/04/2010 : Alerting multiple mail recipients
        oldRuleId = eventRuleDB.RuleId;
 
        eventRuleDB.RuleId = this.parmCreatedRuleId();
        eventRuleDB.insert();
        eventRuleDB.filterQuery(this.queryrun().query());
        eventRuleDB.alertField([tmpEventAlertField]);
        eventRuleDB.typeValue(packedEventType);
        eventRuleDB.contextInfo(this.packContextInfo(eventRuleDB));
 
        this.parmCreatedRuleId(eventRuleDB.RuleId);
 
        // KeSae : 21/04/2010 : Alerting multiple mail recipients
        // Since the RuleId changes during this process, update the link in the recipient table
        NVMPEventRuleRecipients::updateRuleIdLink(oldRuleId, eventRuleDB.RuleId);
 
        ttscommit;
 
        this.checkForeignKey();
    }
    catch (Exception::Deadlock)
    {
        retry;
    }
    catch (Exception::UpdateConflict)
    {
        if (appl.ttsLevel() == 0)
        {
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::UpdateConflictNotRecovered;
            }
            else
            {
                retry;
            }
        }
        else
        {
            throw Exception::UpdateConflict;
        }
    }
 
}

 

The following change is adding the recipients when mailing. Class EventActionEmail, method Execute :

mappings = this.createEmailParameterMap(alertInbox,eventType,eventRule);
 
        xmlParameters = EventActionEmail::createEmailParameterXml(mappings);
 
        if (eventParameters.AlertTemplateId)
        {
            SysEmailTable::sendMail(eventParameters.AlertTemplateId
                                ,   userInfo.Language
                                ,   sysUserInfo.Email
                                ,   mappings
                                ,   ''
                                ,   xmlParameters
                                ,   true
                                ,   eventRule.UserId
                                ,   true);
 
            // KeSae : 21/04/2010 : Alerting multiple mail recipients
            NVMPEventRuleRecipients::sendMail(eventRule.RuleId
                                            , eventParameters.AlertTemplateId
                                            , mappings
                                            , xmlParameters);
        }
        else
            throw error("@SYS94918");

 

When the email for this alert is sent, every user in the list will receive a link to the alert by email.

Download the xpo here

Warning: count(): Parameter must be an array or an object that implements Countable in /customers/5/2/1/ksaelen.be/httpd.www/wordpresses/dynamicsaxblog/wp-includes/class-wp-comment-query.php on line 399

5 thoughts on “Dynamics Ax Alerting multiple users (By email)

  1. Not a bad sample…there are some bugs though. Relations aren’t setup so the delete action doesn’t work. Modifying additional recipients doesn’t appear to be working.

    I was hoping to just grab and go with this and after a few tweaks I could.

    Thanks!

  2. Thanks! I’m going to change it up a bit but this is a great start!

  3. Hi,

    I am also searching same functionality like how to send multiple Users (Security role Id – group users) through PopUp and Email in Ax 2012. Eg- I have added new field Security role in “Create alert Rule form” and selecting Security role Id(like Account manager) so Pop up and alert will go all users of (Account mangaer Group).

    Can you please send me details for sending Pop Up message to MultiPle user.

    its very very urgent as this functionality is over due for development.

    Thanks in advance

  4. Sir
    I have Configured Email Alerts in my system.I have configured the Email Template.I have configured it for ‘Credit Limit Change’.Means it’s a change based alert.So i also need the’User Name’ or User Id who has change the value of field.So i want to Know if there is any Merge DataType or any other way by which I can get the User Name in Email Message.Give me some solution Sir
    Thanks in advance.

  5. Hi,
    I want to add one more user in create alert rule. Or I want to say that I want to show popup notification on two users so I have to add another field of userId. I am working on AX 2012 R2.
    Thanks in advance.

Leave a Comment Yourself

Your email address will not be published. Required fields are marked *