SysOperation frame work in ax2012

            Sysoperation frame work in ax2012  is used for run our business logic inter actively or   periodically by scheduling batch jobs. in ax batch server.  

Sysoperation framework follows MVC pattern which is model view and controller 

Model ; model  is a member which intarct with view to get the input parameters and it is also co-ordinate with controller for execte the busines logic.

view; view is for display purpose.Ui builder class is worked as view in ax 2012

controller; Controller is used for execute  our busines logic.

    apart from that in sysoperation framwork  we have some classes which are exactly worked as mvc pattern

those are 

1.sysopeartion contarct class 

2.sysopeartion serviece class

3.sysopeartioncontroller class

4.sysopeartion uibuilder class

  here i have a requirement that i want to insert lines for price/disc agrement journal by using existing posted journals.

For that i have created a contract class having parameters current journals and posted journals.

here the code for sysopeartion 


Data Contract class :

          To create  Datacontarct class we have to use DataContractAttribiute on the top of the class and 

and we have to mention DatamemberAttribute on the top of the Methods.

Additionally we can use UiBuilder class for forther refferences like lookups,validations,modifications etc.

  Code snippet:

1.declaring Datacpontract class

                         [DataContractAttribute,

                             SysOperationContractProcessingAttribute(classstr(DaxPricediscUiBuilder))]

                    class DaxPriceDiscContract

                    {

                           str  CurrentJournal;           //for unbond controls we mention datatype 

                           str  PostedJournals;             // for bonded edts

                     }

2.declaring Parm Methods for user input. These methods will create parmaetrs of dailoge form for user interactions.

                                    [DataMemberAttribute,

                                SysOperationLabelAttribute(literalStr(" current journal")), -------> label

                                SysOperationHelpTextAttribute(literalStr("for current journal lines")),---->helptext

                                SysOperationDisplayOrderAttribute('1')] 


                            public str parmCurrentJournal(str _currentJournal = currentJournal)

                            {

                             currentJournal =_currentJournal;

                            return currentJournal;

                           }

           And one more parmmethod

[DataMemberAttribute,

SysOperationLabelAttribute(literalStr(" Posted journal")),

SysOperationHelpTextAttribute(literalStr("for insert journal lines")),

SysOperationDisplayOrderAttribute('2')]

public str parmPostedJournals(str _postedJournals = postedJournals)

{

    postedJournals =_postedJournals;

    return postedJournals;

}

UI BUILDER CLASS: 

   my requiermnt is I want lookup for posted journal field in dailoge box.so that i have used uibuilder class.
 Uibuilder class is extented from SysOperationAutomaticUibuilder;

1.create UiBuilder class and declare Contract class.
              

class DaxPricediscUiBuilder extends SysOperationAutomaticUIBuilder
{
    DaxPriceDiscContract DaxPriceDiscContractloc;
}

2. Build method for perfom operatiopn on Contract class

 

   Public void build()
{
    DaxPriceDiscContractloc = this.dataContractObject();
    this.addDialogField(methodStr(DaxPriceDiscContract,parmCurrentJournal),DaxPriceDiscContractloc);
    this.addDialogField(methodStr(DaxPriceDiscContract,parmPostedJournals),DaxPriceDiscContractloc);

}

3. Normal lookup method.

                                Public void lookupPostJour(FormStringControl _formStringControl)

{

    Query query = new Query();

    QueryBuildDataSource qbds;

    QueryBuildRange qbr;

    SysTableLookup lookup;

    lookup = SysTableLookup::newParameters(tableNum(PriceDiscAdmTable),_formStringControl);

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

    qbr=qbds.addRange(fieldNum(PriceDiscAdmTable,Posted));

    qbr.value(SysQuery::value(NoYes::Yes));

    lookup.parmQuery(query);


    lookup.addLookupfield(fieldNum(PriceDiscAdmTable,JournalNum));

    lookup.addLookupfield(fieldNum(PriceDiscAdmTable,JournalName));

    lookup.performFormLookup();

4. We will create a PostBuild Method.


Public void PostBuild()

{

    DialogField dgpostedJour;

    dgpostedJour=this.bindInfo().getDialogField(this.dataContractObject(),

    methodStr(DaxPriceDiscContract,parmPostedJournals));

    dgpostedJour.registerOverrideMethod(methodStr(FormStringControl,lookup),

    methodStr(DaxPricediscUiBuilder,lookupPostJour),this);

}

 So now we will apply this Uibuilder class on the top of the Contract Class. So that it will extract the Uibuilder class methods.

SERVICE CLASS:

 Now Iam Creating service class which  used to write our busines logic to perform our operation.

Note; Service class is optional class.we can also use controller class to run our business logic.But for the better performnce, as to reduce the overloading in contarct class we wil use service class.

1. class declaration 

class DaxPricdiscService extends SysOperationServiceBase

{

}

2.add one method to perform our logic


[SysEntryPointAttribute]        // mandotary to get the values from dailoge

public  void testContract(DaxPriceDiscContract _daxPriceDiscContract)

{

    PriceDiscAdmTrans priceDiscAdmTrans,priceDiscAdmTransLOC;

    RecordInsertList insertRecords;

    insertRecords = new RecordInsertList(tableNum(PriceDiscAdmTrans));

    while select priceDiscAdmTransLOC

        where priceDiscAdmTransLOC.JournalNum==_daxPriceDiscContract.parmPostedJournals()

    {

        if (priceDiscAdmTransLOC)

        {

         // for traditional insert follow this one. here im using RecordInsertList 

            //priceDiscAdmTrans.JournalNum=_daxPriceDiscContract.parmCurrentJournal();

            //priceDiscAdmTrans.inventdimid=priceDiscAdmTransLOC.inventdimid;

            //priceDiscAdmTrans.itemrelation=priceDiscAdmTransLOC.itemrelation;

            //priceDiscAdmTrans.itemcode=priceDiscAdmTransLOC.itemcode;

            //priceDiscAdmTrans.amount=priceDiscAdmTransLOC.amount;

            //priceDiscAdmTrans.fromdate=priceDiscAdmTransLOC.fromdate;

            //priceDiscAdmTrans.accountcode=priceDiscAdmTransLOC.accountcode;

            //priceDiscAdmTrans.relation=priceDiscAdmTransLOC.relation;

            //priceDiscAdmTrans.currency=priceDiscAdmTransLOC.currency;

            insertRecords.add(priceDiscAdmTransLOC);

            info('inserted');

        }

    }

    insertRecords.insertDatabase();

    info('parm dailoge test');

}

 CONTROLLER CLASS:

          Controller is the main class to execute our business logic.Controller class must have one main method, new method,Construct method.

Here code snippet.

1.Class Declartion

[    SysOperationJournaledParametersAttribute(true) ]

class DaxPricediscController extends SysOperationServiceController

{

                         //declare all variables which will use in your  opeartion 

     Common                  callerrecord;

    DaxPricediscController           controller;

    DaxPriceDiscContract    daxPriceDiscContract;

    PriceDiscAdmTable       priceDiscAdmTable;

    PriceDiscAdmTrans       priceDiscAdmTrans;

   }

2. My requiremnt is i want to pic the current record from a form and insert its line details.

So that im using args Parameters and methods./

   1.add parmCallerRecord

  public Common parmCallerRecord(Common _callerRecord = callerRecord)

{

                        //used to get the selected record table 

    callerRecord = _callerRecord;


    return callerRecord;

2  add initFromCaller

.private void initFromCaller()

{

                        // getting object of contract class 

    daxPriceDiscContract = this.getDataContractObject();

    switch (this.parmCallerRecord().TableId)

    {

                            // initilizing parmcallerrecord 

        case tableNum(PriceDiscAdmTrans) :

           priceDiscAdmTrans = this.parmCallerRecord() as PriceDiscAdmTrans;

            daxPriceDiscContract.parmCurrentJournal(priceDiscAdmTrans.journalnum);

            break;

    }

}

3.  newFromArgs

public static DaxPricediscController newFromArgs(Args _args)

{

                                // pasing args   to the controller class

    DaxPricediscController           controller;

    IdentifierName                  className;

    IdentifierName                  methodName;

    SysOperationExecutionMode       executionMode;


    [className, methodName, executionMode] = SysOperationServiceController::parseServiceInfo(_args);

    if (_args.record())

    {

        executionMode = SysOperationExecutionMode::Synchronous;

    }

    controller = new DaxPricediscController(className, methodName, executionMode);

    controller.parmArgs(_args);

    controller.parmCallerRecord(_args.record());

    return controller;

}

4.refreshCallerRecord

protected void refreshCallerRecord()

{

                                // used to refresh the caller record 

    FormDataSource callerDataSource;

    if (this.parmCallerRecord() && this.parmCallerRecord().dataSource())

    {

        callerDataSource = this.parmCallerRecord().dataSource();

        callerDataSource.research(true);

    }

}

5.new method

            // in the paranthesis declare classes and methods and execution mode as parameters

void new(IdentifierName _className = classStr(DaxPricdiscService),

IdentifierName _methodName = methodStr(DaxPricdiscService, testContract),

SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous

)

{

    super(_className, _methodName, _executionMode);

// by passing service class in these methods we will creating reference for our contract class as well so that when we running our controller class it will show us dailoge

   this.parmClassName(classStr(DaxPricdiscService));

   this.parmMethodName(methodStr(DaxPricdiscService,testContract));


 5.Main Method.

    as we know main method used for creating  instance object of the class and opertion will execute or starts from Main method only.

  Public static void Main(Args _args)

{

        DaxPricediscController daxPricediscController= new DaxPricediscController();

     daxPricediscController = DaxPricediscController ::newFromArgs(_args);

         //daxPricediscController.parmArgs(_args);

        daxPricediscController.initFromCaller();

        daxPricediscController.refreshCallerRecord();

      // manodtary  to start our controller class operations

        daxPricediscController.startOperation();

}

6.Create a instance of Data contract class. so that it is easy to access Data Contract class.

     public DaxPriceDiscContract parmDaxPriceDiscContract(DaxPriceDiscContract _DaxPriceDiscContract = daxPriceDiscContract)

{

    daxPriceDiscContract = _DaxPriceDiscContract;

    return daxPriceDiscContract;

}

So its done for creating classes and methods.. so now we will going to add our controller class to a Action Menu iterm.

 in the action menu item properties we have to mention following properties 

    

    And then compile your project and open the menu item

   U will Get a dailoge like this  

    


      Keep Daxing.....!








 




   

1 comment:

  1. Good explanation about SysOperation frame work
    Best of luck
    Keep going with more information

    ReplyDelete