Interview Questions

Monday, May 12, 2014

Alerts through code in ax 2009

static void alerts(Args _args)
{
    EventInbox          inbox;
    ;
 info(strfmt("%1", syscompanyuserinfo::emplId2UserId('Rahul')));
    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();
}

Through Code Alerts:-
1.smmActivities:-
  On the table Update method:-
  if (this.ResponsibleEmployee)
    SalesResponsibleAlerts::getAlerts(this.ResponsibleEmployee, this.RecId,this.TableId, fieldnum(SmmActivities, ResponsibleEmployee));
    ttscommit;
2.Create one class:-
class SalesResponsibleAlerts
{
}
Public Static void getAlerts(EmplId _emplId, RecId  _recId, TableId    _TableId, fieldId   _FieldId)
{
    EventInbox          inbox;
    smmleadtable        lead;
    CaseManagement      caseMgmt;
    smmOpportunityTable SmmOpp;
    smmActivities       SmmAct;
    ;
    inbox.initValue();
    inbox.ShowPopup     = NoYes::Yes;
    inbox.Subject       = strfmt("Field Responsible in table %1 has changed", tableid2name(_TableId));
    inbox.Message       = strfmt("Field Responsible in table %1 has changed", tableid2name(_TableId));
    if (_tableid == tablenum(smmleadtable))
    {
        Select firstonly lead
            where lead.RecId    == _recId;
        inbox.AlertedFor    = strfmt("Lead ID: %1, %2", lead.LeadId, lead.LeadDescription);
    }
    else if (_tableid == tablenum(TCC_CaseManagement))
    {
        Select firstonly caseMgmt
            where caseMgmt.RecId    == _recId;
        inbox.AlertedFor    = strfmt("Case ID: %1, %2", caseMgmt.CaseId, caseMgmt.CaseSubject);
    }
    else if (_tableid == tablenum(smmOpportunityTable))
    {
        Select firstonly SmmOpp
            where SmmOpp.RecId    == _recId;
        inbox.AlertedFor    = strfmt("Opportunity ID: %1, %2", SmmOpp.OpportunityId, SmmOpp.Subject);
    }
    else if (_tableid == tablenum(smmActivities))
    {
        Select firstonly SmmAct
            where SmmAct.RecId    == _recId;
        inbox.AlertedFor    = strfmt("Activity ID: %1, %2", SmmAct.ActivityNumber, SmmAct.Category);
    }
    inbox.SendEmail     = false;
    inbox.UserId        = syscompanyuserinfo::emplId2UserId(_emplId);
    inbox.TypeId        = classnum(EventType);
    inbox.AlertTableId  = _TableId;
    inbox.AlertFieldId  = _FieldId;
    inbox.TypeTrigger   = EventTypeTrigger::FieldChanged;
    inbox.CompanyId     = curext();
    inbox.InboxId       = EventInbox::nextEventId();
    inbox.AlertCreatedDateTime = DateTimeUtil::getSystemDateTime();
    inbox.insert();
}

No comments:

Post a Comment