Monday, September 26, 2011

Custom Build notifications and popup in Axapta

Custom Build Notifications:
Usage: This method used to create custom build notifications and Popup in Dynamics AX
Learned: Today I was assigned by this task. The task was to give notification to every company and user (the company and user has been already selected in parameter form in AR) when I post payment journal in Accounts receivable module. So here I have two situations
1.       Purely hard code everything to create notification when I post journal in payment journal
2.       Otherwise cross code the default AX functionality in notifications (Alert rule).
I choose the second options it’s a far simpler than first one. Ok how did I do it? (If it has some mistakes and bugs. please comment on that) here follow the steps
·         Notifications are retrieved from the Event Inbox table.
·         We need to insert one perfect record in Event inbox then problem solved. System automatically retrieves and gives the notification from Event Inbox table.
·         Ok how to insert the perfect record
1.       I just created new table method in Event Inbox “InitfromPaymentJournal”. Here I had written the following code.

static void initFromPaymentJournal(DataAreaId Companyid,LedgerJournalId JournalId)
{
    EventInbox  EventInbox,inbox;
    SysUserInfo SysUserInfo;
    ;

    ttsBegin;
    while select SysUserInfo order by SysUserInfo.Id where SysUserInfo.Id!=""
    //while select maxof(inboxId) from inbox where
    {
        select maxof(inboxId) from inbox;
        EventInbox.InboxId                                        =   EventInbox::nextEventId();
        EventInbox.CompanyId                                =   Companyid;
        EventInbox.AlertTableId                              =   212;//2271;
        EventInbox.AlertCreatedDateTime         =   DateTimeUtil::utcNow();
        EventInbox.ParentTableId                           =   212;//2271;
        EventInbox.IsRead                                          =   NOYES::No;
        EventInbox.Subject                                        =   "Payment Journal Posting Created";
        EventInbox.AlertedFor                                 =   "Post created";
        EventInbox.UserId                                          =   SysUserInfo.Id;
        EventInbox.ShowPopup                               =   NOYES::Yes;
        EventInbox.Visible                                          =   NOYES::Yes;
        EventInbox.Message                                     =   strfmt("Paymentjournal Post created for %1",JournalId);
        EventInbox.insert();
    }

    ttsCommit;
}

2.       InboxId is the mail field in event inbox table. I used the default method in Event inbox table. You can check it out, I sent the company Id (the notification show in which company) and Journal id (Payment journal id) as arguments. Other things you can understand by go through it.
3.       That’s it now you can enjoy the custom notifications created through X++ code. If you can’t get the automatic notification popup you can just go through my previous post.
4.       But In notification form you can’t find the record by clicking Go to Origin button. If anybody know this please guide me. Thanks.

3 comments:

  1. Where is link to "my previous post"?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. if error By clicking Go to Origin button, modify method "drilldown" from class "EventContextDrillDown" as below

      replace "buffer = SysDictTable::findFromKeyData(inbox.ParentTableId,inbox.keyFieldData());" with the below condition

      if(tableNum([your EventInbox.AlertTableId])== inbox.AlertTableId)
      {
      args.record([target form datasource table]);
      new MenuFunction(menuitemDisplayStr([display MenuItem calling target form]),MenuItemType::Display).run(args);
      return;
      }
      else
      {
      buffer = SysDictTable::findFromKeyData(inbox.ParentTableId,inbox.keyFieldData());
      }

      Delete