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.
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