Monday, November 6, 2023

Code to create a Simple BatchJob with Records to include filter in D365F&O X++

/// <summary>

/// The <c>MCRFTCEventProcessBatch</c> class handles processing FTC events in batch.

/// </summary>

class MyBatchJobBatch extends RunBaseBatch implements BatchRetryable

{

   // Packed variables

   int                 dummy;

   // Dialog fields

   QueryRun                            projectQueryRun;

 

   #define.CurrentVersion(2)

   #localmacro.CurrentList

       dummy,

       startDate,

       endDate

   #endmacro

   /// <summary>

   /// Adds the <c>SalesID</c> to the dialog box

   /// allowing the user to run a batch over the selected

   /// <c>SalesID</c>.

   /// </summary>

   /// <returns>

   /// The dialog box box.

   /// </returns>

   public Object dialog()

   {

       DialogRunbase               dialog; 

       //Setup the dialog

       dialog = super();

       dialog.caption("Simple Batch Job");

       return dialog;

   }

   /// <summary>

   /// Retrieves the user entered values from dialog form.

   /// </summary>

   /// <returns>

   /// true if the values are retrieved successfully; otherwise, false.

   /// </returns>

   public boolean getFromDialog()

   {

       boolean ret;

       ret = super();

       return ret;

   }

   protected void initQuery()

   {

       QueryBuildDataSource qbds;

       Query                query = new Query();

 

       query.allowCrossCompany(true);

       qbds = query.addDataSource(tableNum(CustTable));

       projectQueryRun = new QueryRun(query);

   }

   protected void new()

   {

       super();

       this.initQuery();

   }

   public container pack()

   {

       return [#CurrentVersion, #CurrentList];

   }

   boolean prompt()

   {

       return super();

   }

   public QueryRun queryRun()

   {

       return projectQueryRun;

   }

   public boolean showQueryValues()

   {

       return true;

   }

   public boolean unpack(container packedClass)

   {

       Version version = runbase::getVersion(packedClass);

       switch (version)

       {

           case #CurrentVersion:

               [version, #CurrentList] = packedClass;

               break;

           default:

               return false;

       }

       return true;

   }

    public static MCRFTCEventProcessBatch construct()

   {

       return new MCRFTCEventProcessBatch();

   }

   public static ClassDescription description()

   {

       return "Simple Batch Job";

   }

   public static void main(Args args)

   {

       MyBatchJobBatch myBatchJobBatch = new myBatchJobBatch();

       myBatchJobBatch.parmInBatch(false);

 

       if (myBatchJobBatch.prompt())

           myBatchJobBatch.runOperation();

   }

 

   /// <summary>

   /// Describes whether the class is designed for execution in a new session.

   /// </summary>

   /// <returns>

   /// false.

   /// </returns>

   protected boolean canRunInNewSession()

   {

       return false;

   }

   /// <summary>

   /// Specifies if the batch task is retryable for transient exceptions or not.

   /// </summary>

   /// <returns>

   /// If true is returned, the batch task is retryable, otherwise it is not.

   /// </returns>

   [Hookable(false)]

   final boolean isRetryable()

   {

       return true;

   }

}

Output :







No comments:

Post a Comment