Freitag, März 16, 2007

Send message to online user in Dynamics AX 4.0 (quick & dirty)

I am missing the functionality to send messages to online users that existed in Axapta 3.0 and is now gone. Well, I thought you could use the "Alert" functionality introduced in DAX 4.0.
What to do:
1. make sure the user options are configured correctly (that means: set "Time poll interval" to 1 minute, set "Show popup" to "For all event rules")
2. make a button in the online user form that will open a dialog where you could enter your text
3. send the message to all users selected in the online user form datasource

Here is a little job that creates an alert for a user. Remember this is a quick & dirty solution, so there are some drawbacks:
* you will get an error in the alert form on the second tab
* the message will only be displayed about 15 sec and disappears afterwards (you can check FRM EventAttentionGrabber to change that. Check methods fadeIn and fadeOut for variable opacity. This should give you a hint on how to display the form longer)
* the message will stay as unread until the user marks it as read

So you see there's lot of room to improve it... 8-)

Remember also to replace the "curuserid()" with the user id you want the alert to be sent to.

This is merely meant as an idea on how you can achieve sending messages to a user.

static void sendAlert(Args _args)
EventInbox inbox;
EventInboxId inboxId;

inboxId = EventInbox::nextEventId();


inbox.ShowPopup = NoYes::Yes;
inbox.Subject = "Message to online user";
inbox.Message = "Message you want to send to user";
inbox.SendEmail = false;
inbox.UserId = curUserID();

inbox.InboxId = inboxId;

inbox.AlertCreatedDate = systemdateget();

inbox.AlertCreateTime = timeNow();




Thomas hat gesagt…

Hi Helmut

I was interested in your post and expanded the code a bit, so that it is possible to send data. The problem I still have is that I have difficulty in generating an EventRule dynamically (see code below TODO:) i.e. it is nescessary to generate an alert on the table you want to send and rename the RuleId to _TableName for the following code to work. I hope a reader of your blog can expand this code ...
Thomas Widmer

static void Alert( str _subject,
str _message,
UserId _recipent,
Args _args)
EventInbox inbox;
EventActionAlert eventActionAlert = New EventActionAlert();
EventRule eventRule;
EventContextInformation context;

void assignParams()
{//the setting in the eventRule are dynamically changed to fit the dynamic alert
eventRule.UserId = _recipent;
eventRule.ShowPopup = NoYes::Yes;
eventRule.Subject = _subject;
eventRule.Message = _message;
eventRule.SendEmail = NoYes::Yes;
eventRule.Enabled = NoYes::No; //not a standard event rule
//create a custom eventRule
eventRule = EventRule::find("_" + tableid2name(_args.dataset()),true); //the eventRule has the name of the calling table
//to generate an alert a corresponding eventRule must exist
eventRule.RuleId = "_" + tableid2name(_args.dataset());
throw error("Dynamic creation of event rule has not been implemented","",SysInfoAction_Editor::newStackClass("BWSend"));
//open issues: how to dynamically create an eventRule
//TODO: generate the corresponding eventRuleData

context = EventContextInformation::construct();

eventActionAlert.execute(eventRule,new EventTypeCUD(),_args.record(),inbox);

Steve hat gesagt…

static void SendMessage(Args _args)
SysClientSessions sysClientSessions;
SysCompanyUserInfo sysCompanyUserInfo;
EmplTable emplTable;
SysMailer mailer;
SysEmailParameters parameters = SysEmailParameters::find();
mailer = new SysMailer();
mailer.subject("Arrêt d'Axapta");

if (parameters.SMTPRelayServerName)

mailer.body("Axapta sera mis à jour et donc inaccessible entre 12h15 et 12h45, veuillez prendre vos dispositions, merci.");

while select sysClientSessions
where sysClientSessions.Status == 1
join sysCompanyUserInfo
where sysCompanyUserInfo.UserId == sysClientSessions.userId
join emplTable
where emplTable.EmplId == sysCompanyUserInfo.EmplId

Steve hat gesagt…

don't forget to clear the addresses before appending a new one: