Create batch job with parameter and add validation on parameter using SysOperation framework


 

Creating batch job with parameter using SysOperation framework and add validation on paramete

Today, we will create batch job with parameter and add validation on parameter using SysOperation framework.

Here are the requirement and its development.

Requirement: We wants to create a batch job with two parameter. If number of days’ parameter & SQL query haven’t values, batch job wouldn’t run and system throw an error message before executing the batch job.

 

To achieve the above requirement we have created three classes that are – Service, Contract and Controller class


1. Contract class: This class used for to create parameter and add validation on parameter.

To add the validation on contract class; add implements keyword with contract class and override validate() method.

 

     implements SysOperationValidatable

     public boolean validate()

    {

       // validation logic

    }

 

[DataContractAttribute]

public class XXX_Contract implements SysOperationValidatable

{

    Str        sqlStatement;

    int        numberOfDays;
   

    [

        DataMemberAttribute,

        SysOperationLabelAttribute(literalStr(“SQL statement")),

        SysOperationHelpTextAttribute(literalStr(“SQLStatementHelp")),

        SysOperationDisplayOrderAttribute('2')

    ]

    public str parmSQLStatement(str _sqlStatement = sqlStatement)

    {

        sqlStatement = _sqlStatement;

        return sqlStatement;

    }

 

    [DataMemberAttribute,

        SysOperationLabelAttribute(literalStr("Number of day")),

        SysOperationHelpTextAttribute(literalStr("NumberOfDay")),

        SysOperationDisplayOrderAttribute('1')]

    public int parmNumberOfDay(int _numberOfDays = numberOfDays)

    {

        numberOfDays = _numberOfDays;

 

        return numberOfDays;

    }

 

    /// <summary>

    ///    Determines whether the parameters are valid.

    /// </summary>

    /// <returns>

    ///    true if the parameters are valid; otherwise, false.

    /// </returns>

    public boolean validate()

    {

        boolean isValid = true;

 

        if (numberOfDays <= 0)

        {

            isValid = checkFailed(“Number of day must be greater than 0");

        }

 

        if (sqlStatement == '')

        {

            isValid = checkFailed("Enter valid SQL statement");

        }

 

        return isValid;

    }

 

}


2.       Service class: Service class used to execute actual business logic

 

public class XXX_Service extends SysOperationServiceBase

{

public void processOperation(XXX_Contract _contract)

    {


        Str SQLStatement   = _contract.parmSQLStatement();

        Int NoOfday = contract.parmNumberOfDay();


        Info(SQLStatement, NoOfday);

      // Add business logic

  }

}

 

3.  Controller class: Controller class used to drive service class and here we define batch job execution behavior.

 

class XXX_Controller extends SysOperationServiceController

{

    protected void new()

    {

    // call service class and service class method

       super(classStr(XXX_Service), methodStr(XXX_Service,      processOperation), SysOperationExecutionMode::Synchronous);
      
    }

 

    /// <summary>

    /// Construct XXX_Controller class

    /// </summary>

    public static XXX_Controller construct(SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous)

    {

        XXX_Controller controller;

        controller = new XXX_Controller();

        controller.parmExecutionMode(_executionMode);

        return controller;

    }


    public static void main(Args _args)

    {

        XXX_Controller controller;

 

        controller = XXX_Controller::construct();

        controller.parmArgs(_args);

        controller.startOperation();

    }

 

    /// <summary>

    /// Caption of a batch job

    /// </summary>

    public ClassDescription defaultCaption()

    {

        return “SysOperation batch job example";

    }

 

}

Comments

Popular posts from this blog

Execute D365 F&O SSRS report with parameter and upload report output on Azure blob storage using X++

Microsoft D365 F&O: Remove custom models from deployable package

Generate Text/CSV/DAT file using X++ and upload on Azure blob storage