Push Notifications: To Create a Built-In Query Definition

The following activity shows you how to create a built-in query definition for push notifications.

Story

Suppose that you need to configure MYOB Acumatica to send push notifications for a query that is defined as a class in the source code of the application—that is, for a built-in definition of the query.

Process Overview

In a project of your MYOB Acumatica extension library, you will define a class that implements the PX.PushNotifications.Sources.IInCodeNotificationDefinition interface. You will then build the project of your MYOB Acumatica extension library and test the built-in query definition.

System Preparation

Before you begin performing the steps of this activity, do the following:

  1. Prepare an MYOB Acumatica instance with any predefined dataset. You can do it by completing the following prerequisite activity: Instance Deployment: To Deploy an Instance with Demo Data.
  2. Create a customization project, such as in the Customization Projects: To Create a Customization Project prerequisite activity.
  3. Create an extension library, as described in the To Create an Extension Library prerequisite activity.
Tip:
You can find the final code of this activity in the TestInCodeDefinition.cs file in the Help-and-Training-Examples repository on GitHub.

Step 1: Creating a Built-In Query Definition

To create a built-in query definition, do the following:

  1. In a project of your MYOB Acumatica extension library, define a class that implements the PX.PushNotifications.Sources.IInCodeNotificationDefinition interface. The following code demonstrates the definition of such a class.
    using PX.PushNotifications.Sources;
    
    public class TestInCodeDefinition : IInCodeNotificationDefinition
    {
    }
    Tip:
    Make sure references to the PX.Data.dll, PX.Data.BQL.Fluent, and PX.PushNotifications.dll libraries are included in your project.
  2. In the class that implements the IInCodeNotificationDefinition interface, implement the GetSourceSelect() method of the interface so that the method satisfies the following requirements:
    • The method must return a tuple of a BqlCommand object, which defines the data query, and a PXDataValue array, which defines the parameters that should be passed to the query.
    • The data query that the method defines should adhere to Push Notifications: Recommendations for the Data Queries.

    The following example shows the GetSourceSelect() method implementation.

    using PX.Data;
    using PX.PushNotifications.UI.DAC;
    using System;
    using PX.Data.BQL.Fluent;
    using PX.PushNotifications.Sources;
    
    public class TestInCodeDefinition : IInCodeNotificationDefinition
    {
        public Tuple<BqlCommand, PXDataValue[]> GetSourceSelect()
        {
            return
              Tuple.Create(
                SelectFrom<PushNotificationsHook>.
                LeftJoin<PushNotificationsSource>.
                  On<PushNotificationsHook.hookId.
                    IsEqual<PushNotificationsSource.hookId>>.View
                .GetCommand(), new PXDataValue[0]);
        }
    }
  3. In the class that implements the IInCodeNotificationDefinition interface, implement the GetRestrictedFields() method of the interface so that the method satisfies the following requirements:
    • The method must return an array of IBqlField-derived types, which contains the fields that should be returned from the query.
    • If you need to return all fields, the method must return null.

    The following code shows an example of the implementation of the GetRestrictedFields() method.

    using PX.Data;
    using PX.PushNotifications.UI.DAC;
    using System;
    using PX.Data.BQL.Fluent;
    using PX.PushNotifications.Sources;
    
    public class TestInCodeDefinition : IInCodeNotificationDefinition
    {
    ...
        public Type[] GetRestrictedFields()
        {
            return new[]
            {
              typeof(PushNotificationsHook.address),
              typeof(PushNotificationsHook.type),
              typeof(PushNotificationsSource.designID),
              typeof(PushNotificationsSource.inCodeClass),
              typeof(PushNotificationsSource.lineNbr)
            };
        }
    }
  4. Build the project of your MYOB Acumatica extension library.

Step 2: Testing the Built-In Query Definition

On the Built-In Definitions tab of the Push Notifications (SM302000) form, create a push notification definition and make sure that you can select the new built-in query definition by its class name in the Class Name column. The class of the built-in query definition, which implements the IInCodeNotificationDefinition interface, is detected by the system and automatically added to the list of classes available for selection on the tab.

Tip:
After you have defined a push notification definition that uses a built-in query definition on the Push Notifications form, you can obtain the results of the data query defined with a built-in query definition by using the following endpoint: http(s)://<MYOB Acumatica instance URL>/PushNotifications/<full class name of the built-in query definition>.

For example, suppose that you want to retrieve the results of the data query defined with the PX.PushNotifications.Sources.TestInCodeDefinition class from a local MYOB Acumatica instance with the name AcumaticaDB. You should use the following URL to obtain the data: http(s)://localhost/AcumaticaDB/PushNotifications/PX.PushNotifications.Sources.TestInCodeDefinition. The endpoint returns the data in JSON format.