Create RunbaseBatch Class with Query window selection in Ax 2009,Ax 2012

Step 1: Create a runbasebatch class with all the needed methods

Step 2: Override the initParmDefault() method

public void initParmDefault()
{
Query query = new Query();
QueryBuildRange queryBuildRange;
QueryBuildDataSource queryBuildDataSource;
;
// query.addDataSource(tablenum(CustInvoiceJour));
queryBuildDataSource=query.addDataSource(tableNum(CustInvoiceJour)); //Add Query
queryBuildRange=queryBuildDataSource.addRange(FieldNum(CustInvoiceJour,OrderAccount));
queryrun = new SysQueryRun(query);

super();
}

QueryRun queryrun()
{
return queryrun;
}

Step 3: In Run method you can apply your logic

public void run()
{
;
queryRun = this.queryRun();
queryRun.query().dataSourceNo(1).addRange(fieldnum(CustInvoiceJour,InvoiceDate)).value(queryValue(fromDate)+ ‘..’+ queryValue(toDate));
while(queryRun.next())
{
custInvoiceJour = queryRun.get(tablenum(CustInvoiceJour));
info(strfmt(“%1,%2”,custInvoiceJour.InvoiceId,custInvoiceJour.InvoiceDate));

}
}

BatchwithQuery

Advertisements

Import Csv file to Ax 2012 using X++ code and as Runbase batch

class John_RBTestClass extends RunBaseBatch
{
}

client server static ClassDescription description()
{
return “Johnkrish Batch Test”;
}

static void main(Args _args)
{
John_RBTestClass objClass = new John_RBTestClass();
//prompt for runbase framework dialog
if (objClass.prompt())
{
//run the process
objClass.run();
}
}

 

public void run()
{
Bill_Copy bc;

#File
IO iO;
CustAccount custAccount;
CustName custname;
str one;
FilenameOpen filename = @’E:\Johnkrish\Johnkrish.csv’;//To assign file name
Container record;
boolean first = true;

str Delimiter = “,”;
int totalRecords;
;
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error(“@SYS19358”);
}

record = iO.read();

while(iO.status() == IO_Status::Ok)

{

record = iO.read();

if(!record)

break;
bc.CustName=conpeek(record, 1);
bc.ItemName=conpeek(record, 2);
bc.insert();

}

}

DATA in .Csv file
John,Mobile
Krish,Phone
Gopal,Purse