hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Tuesday, August 18, 2020

RunBase And Runbase Batch In Ax 2012

RunBase class: 

Create a class CustomerRunbase Which extends from Runbase class. 


class CustomerRunbase extends RunBase 



    CustAccount custAccount; 


    DialogField custDldField; 


}  


Next create a Dialog method in class 


protected Object dialog() 



    DialogRunbase dialog; 


    dialog = super(); 


    dialog = super(); 


    custDldField = dialog.addFieldValue(extendedTypeStr(CustAccount),custAccount); 


    return dialog; 



Override Getfromthedialog method 


public boolean getFromDialog() 



    Query query = new Query(); 


    QueryBuildDataSource qbds; 


    QueryBuildRange qbr,Qbr1; 


    QueryRun qr; 


    SalesTable salesTable; 


    DAXCustDetails  DAXCustDetailsloc; 


    boolean ret; 


    ret = super(); 


    custAccount = custDldField.value(); 


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


    qbr = qbds.addrange(fieldnum(SalesTable,CustAccount)); 


    qbr.value(custaccount); 


    qr = new QueryRun(query); 


    while (qr.next()) 


    { 


        salesTable = qr.get(tableNum(SalesTable)); 


        DAXCustDetailsloc.Customer = salesTable.CustAccount; 


        DAXCustDetailsloc.ItemId   = salesTable.SalesId; 


        DAXCustDetailsloc.insert(); 


    } 


    return ret; 



Create a Pack method 


public container pack() 



    return conNull(); 



Create a unpack method 


public boolean unpack(container packedClass) 



    return true; 



Lastly create a main method for class 


       public static void main(Args args) 



    CustomerRunbase runbase = new CustomerRunbase();


    if(runbase.prompt()) 


    { 


      runbase.run(); 


    } 


 


Try to run this you will get an dialog box with input parameter custaccount  like below image 

 

 

 

 

 

Select a customer “US-004” and press okay. 

You will get an info like this. 

 

Scenario is same as runbase class  


Create a class DaxCustomerRunbase which extends Runbasebatch class 


public class CustomerRunbasebatch extends RunBaseBatch 



    CustAccount         custAccount; 


    DialogField         custdialog; 



Create Dialog and getfromdialog methods 


protected Object dialog() 



    DialogRunbase dialog; 


   dialog = super(); 


    dialog = super(); 


    custdialog = dialog.addFieldValue(extendedTypeStr(CustAccount),custAccount); 


    return dialog; 



public boolean getFromDialog() 



    Query query = new Query(); 


    QueryBuildDataSource qbds; 


    QueryBuildRange qbr,Qbr1; 


    QueryRun qr; 


    SalesTable salesTable; 


    DAXCustDetails  DAXCustDetailsloc; 


    boolean ret; 


    ret = super(); 


    custAccount = custdialog.value(); 


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


    qbr = qbds.addrange(fieldnum(SalesTable,CustAccount)); 


    qbr.value(custaccount); 


    qr = new QueryRun(query); 


    while (qr.next()) 


    { 


        salesTable = qr.get(tableNum(SalesTable)); 


        DAXCustDetailsloc.Customer = salesTable.CustAccount; 


        DAXCustDetailsloc.ItemId   = salesTable.SalesId; 


        DAXCustDetailsloc.insert(); 


    } 


        return ret; 



Create pack and unpack methods as you created in runbase class 


Create a main method 


public static void main(Args args) 



    CustomerRunbasebatch runbase = new CustomerRunbasebatch(); 


    if(runbase.prompt()) 


    { 


      runbase.run(); 


    } 



You can also create few more methods based on your requirement  . 


Methods: 


      CanGoBatch, canGoBatchJournal, initParmDefault,Validate. 


  


Run the class the dialog box opens 


As you can see here Batch Tab highlighted in below image while runbase class we cant find this tab 

 

 

 

  • Press okay and check the result 

 

No comments:

Post a Comment