To Add Additional Information to Push Notifications

In MYOB Advanced or an MYOB Advanced Framework-based application, you can add additional information to push notifications, such as the username of the user that performed the data change or the business date when the data transaction is performed. The additional information can be added to the AdditionalInfo element of notifications in JSON format. For more information on the format of notifications, see Push Notification Format.

Note: The additional information that you add to push notifications is included in all notifications that are sent from the MYOB Advanced instance on which the additional information is configured.

The dictionary of additional information can be implemented in a project of your MYOB Advanced extension library. To add additional information to push notifications, follow the instructions in this topic.

To Add Additional Information to Push Notifications

  1. In a project of your MYOB Advanced extension library, define a class that implements the PX.Data.PushNotifications.ICommitEventEnricher interface.
  2. In the class that implements the ICommitEventEnricher interface, implement the Enrich() method of the interface. In the method, add the properties that you want to be returned in push notifications.
    Note: The Enrich() method is called in the PX.Data.PXTransactionScope.Dispose() method. Therefore, the Enrich() method must not return data that is not accessible in this scope.

    The following code shows a sample implementation of the ICommitEventEnricher interface, which adds the business date and the name of the user to the AdditionalInfo element of notifications in JSON format.

    using PX.Data;
    using PX.Data.PushNotifications;
    
    public class CommitEventEnricher : ICommitEventEnricher 
    { 
      public void Enrich(IQueueEvent commitEvent)          
      { 
        var businessDate = PXContext.PXIdentity?.BusinessDate; 
        var userName = PXContext.PXIdentity?.IdentityName; 
        commitEvent.AdditionalInfo.Add(nameof(businessDate), businessDate); 
        commitEvent.AdditionalInfo.Add(nameof(userName), userName);        
      }      
    }
  3. Build the project of your MYOB Advanced extension library.
  4. Run MYOB Advanced and make sure that when the results of the query change, the application includes the additional information in the AdditionalInfo element of the notifications in JSON format, as shown in the following notification example.
    {
      ...
      "TimeStamp":636295833829493672,
      "AdditionalInfo":
      {
        "businessDate":"2017-05-05T15:16:23.1",
        "userName":"admin"
      }
    }