Create custom Batch job without parameters in D365 X++

 For creating the batch job without parameters in D365 X++ via SysOpertion Framework, Follow the following steps;

1- First Create a menu action button in the project

2-Create an extension of menu and add menu button to the Menu.

3- Create a ABCBatchContract Contract class as shown below;

[DataContract,SysOperationContractProcessing(classStr(SysOperationAutomaticUIBuilder))]

/// <summary>

/// Create getter setter for query

/// </summary>

public class ABCBatchContract

{

    

}


4- Create ABCBatchController Controller Class as shown below;

/// <summary

/// Inventory Blocking batch controller class

/// </summary>

public  class ABCBatchController extends SysOperationServiceController

{

    /// <summary>

    /// Run the Service Opeeration class action

    /// </summary>

    protected void new()

    {

        super(classStr(ABCBatchService),methodStr(ABCBatchService, startProcess));

    }


    public static ABCBatchController newFromArgs(Args _args)

    {

        ABCBatchController  abcBatchController;


        // create a new instance of the controller

        abcBatchController = new ABCBatchController  ();


        abcBatchController.batchInfo().parmBatchExecute(true);


        // initialize from args

        // one of the things this will do is read the "parameters" property from the menu item

        abcBatchController.initializeFromArgs(_args);


        // return a new instance of this controller

        return abcBatchController;


    }


    public static ClassDescription description()

    {

        return "Blocking Description";

    }


    /// <summary>

    /// Main Method

    /// </summary>

    /// <param name = "args">Get records</param>

    public static void main(Args _args)

    {

  

       ABCBatchController abcController = new ABCBatchController();


        abcController = ABCBatchController::newFromArgs(_args);

        abcController.parmClassName(classStr(ABCBatchService));

        abcController.parmMethodName(methodStr(ABCBatchService, startProcess));

        abcController.parmExecutionMode(SysOperationExecutionMode::Synchronous);


        abcController.startOperation();


    }


}


5- Create a Service class ABCBatchService  from which your logic is executed as shown below;


/// <summary

/// Create a SysOperationFramework batch job

/// </summary>

public class ABCBatchService extends SysOperationServiceBase

{

    /// <summary>

    ///  Implement the logic to block the inventory on base of 3 months.

    /// </summary>

    /// <param name = "dataContract">ABCBatchContract</param>

    public void startProcess(ABCBatchContract dataContract)

    {

        

        InventDim inventDim;

        InventSum inventSum;

        date today = today();

        date preQuater = prevQtr(today);

        InventBatch inventBatch;


        str itemFilterFF = 'FF*';

        str itemFilterYN = 'YN*';


        // Get Records from table with available physical greater than zero.

        while select ItemId,AVAILPHYSICAL,INVENTDIMID from inventSum where inventSum.ItemId like itemFilterFF && inventSum.AVAILPHYSICAL > 0 || inventSum.ItemId like itemFilterYN && inventSum.AVAILPHYSICAL > 0

            join PRODDATE,expDate from inventBatch where inventSum.ItemId == inventBatch.ItemId && inventSum.InventBatchId == inventBatch.inventBatchId

        {

            // If expiration date exist then execute above logic else below logic.

            if (inventBatch.expDate)

            {

                if (inventBatch.expDate <= today)

                {

                    InventBlocking inventBlocking;

                    inventBlocking.initValue();



                    inventBlocking.ItemId = inventSum.ItemId;

                    inventBlocking.Qty = inventSum.AVAILPHYSICAL;

                    inventBlocking.BlockingType = InventBlockingType::Manual;

                    inventBlocking.InventDimId = inventSum.INVENTDIMID;

                    inventBlocking.Description =  "Inventory Blocking";


                    ttsbegin;

                    inventBlocking.insert();

                    ttscommit;


                    inventBlocking.clear();

                }


            }

            else

            {

                if (inventBatch.PRODDATE)

                {

                    if (inventBatch.PRODDATE <= preQuater)

                    {

                        InventBlocking inventBlocking;

                        inventBlocking.initValue();



                        inventBlocking.ItemId = inventSum.ItemId;

                        inventBlocking.Qty = inventSum.AVAILPHYSICAL;

                        inventBlocking.BlockingType = InventBlockingType::Manual;

                        inventBlocking.InventDimId = inventSum.INVENTDIMID;

                        inventBlocking.Description =  "Inventory Blocking";


                        ttsbegin;

                        inventBlocking.insert();

                        ttscommit;


                        inventBlocking.clear();

                    }

                }

            }


        }

        info("Inventory Blocking Succeeded");       

    }


}


6- Now build and sync your project.

7- Go to the front-end site and click on the menu action in which menu you have added. and your job form is displayed, then click on the OK button to execute the job.


If you have any confusion or problem, do let us know so we can slove the queries.


Thanks.

Comments

Popular posts from this blog

Create custom workflow in D365 X++

Convert amount from one currency to another currency using X++

How to Create Extended Data Types (EDTs) in Finance and Operations of Dynamics 365 -- F&O Customization Part 2