Thursday, August 7, 2008

Send Alert to user from code in AX 4.0

// To send Alert to User From Code
void sendAlertToUsers()
{
SysMailer mail;
UserInfo UserInfo;
EventInbox inbox;
EventInboxId inboxId;
;

select UserInfo where UserInfo.id == CurUserId();
inboxId = EventInbox::nextEventId();

inbox.initValue();
inbox.ShowPopup = NoYes::Yes; // To show Pop up
inbox.Subject = "Aleart Message Through Code";
inbox.Message = "Testing Alerts";
inbox.AlertedFor = "This alert is just for information(Testing)";
inbox.SendEmail = false;
inbox.UserId = UserInfo.Id;
inbox.TypeId = classnum(EventType);
//Enter Table and Field Details
inbox.AlertTableId = TableNum(EmplTable); // Table for which Alert is Generated
inbox.AlertFieldId = fieldNum(Empltable ,Name); // Field for which Alert is Generated
inbox.TypeTrigger = EventTypeTrigger::FieldChanged;
inbox.CompanyId = CurExt();
inbox.InboxId = inboxId;
inbox.AlertCreatedDate = systemdateget();
inbox.AlertCreateTime = timeNow();
inbox.insert();
}

No comments: