Friday 5 February 2016

Create Alert using X++ code

static void CreateAlertUsingCode(Args _args) 
{ 
EventInbox          inbox; 
; 
inbox.initValue(); 
inbox.ShowPopup     = NoYes::Yes; 
inbox.Subject       = "This is the Alert subject"; 
inbox.Message       = "This is the Alert message"; 
inbox.AlertedFor    = "This alert is just information no links are available"; 
inbox.SendEmail     = false; 
inbox.UserId        = curuserid(); 
inbox.TypeId        = classnum(EventType); 
inbox.AlertTableId  = tablenum(Address); 
inbox.AlertFieldId  = fieldnum(Address, Name); 
inbox.TypeTrigger   = EventTypeTrigger::FieldChanged; 
inbox.CompanyId     = curext(); 
inbox.InboxId       = EventInbox::nextEventId();; 
inbox.AlertCreatedDateTime = DateTimeUtil::getSystemDateTime(); 
inbox.insert(); 
} 


static void Event_sendAlertByCode(Args _args)
{

    EventNotificationSource _source;
    EventNotification       event = EventNotification::construct(EventNotificationSource::Sync);
    InventTable             inventTable;
    ;

    inventTable = InventTable::find('B-R14');  // sample record for which alert is shown

    event.parmRecord(inventTable);
    event.parmUserId(curuserid());      // user for which this alert to be shown
    event.parmDataSourceName('InventTable');  //form datasource
    event.parmMenuFunction(new MenuFunction('InventTable', MenuItemtype::Display));
    event.parmSubject('Test');
    event.parmMessage('Test Event alert');
    event.create();

}

2 comments:

  1. This will be applicable to AX 2012

    ReplyDelete
  2. Do u have code for new alert rule creation in ax 2012 R2 or R3

    ReplyDelete