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.initValue();
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();
inbox.insert();
}
vor 2 Jahren
3 Kommentare:
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
ttsbegin;
eventRule = EventRule::find("_" + tableid2name(_args.dataset()),true); //the eventRule has the name of the calling table
if(!eventRule)
{
//to generate an alert a corresponding eventRule must exist
eventRule.RuleId = "_" + tableid2name(_args.dataset());
assignParams();
eventRule.insert();
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
eventRule.alertField(conNull());
context = EventContextInformation::construct();
context.setPackedArgs(_args);
context.setAlertFormDsNo(1);
context.setEventRuleId(eventRule.RuleId);
eventRule.contextInfo(context.pack());
eventRule.filter(conNull());
}
else
{
assignParams();
eventRule.update();
}
ttscommit;
eventActionAlert.execute(eventRule,new EventTypeCUD(),_args.record(),inbox);
}
static void SendMessage(Args _args)
{
SysClientSessions sysClientSessions;
SysCompanyUserInfo sysCompanyUserInfo;
EmplTable emplTable;
SysMailer mailer;
SysEmailParameters parameters = SysEmailParameters::find();
;
mailer = new SysMailer();
mailer.fromAddress("admin@admin.com");
mailer.subject("Arrêt d'Axapta");
if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,parameters.SMTPPortNumber,parameters.SMTPUserName,SysEmailParameters::password(),parameters.NTLM);
}
mailer.priority(1);
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
{
mailer.tos().appendAddress(emplTable.Email);
mailer.sendMail();
info(empltable.Email);
}
}
don't forget to clear the addresses before appending a new one:
...
{
mailer.tos().clear();
...
Kommentar veröffentlichen