Store Query Range in variables

Hi,

I have the following query and I want to store in two variables fields ‘dtFromDate’ and ‘dtToDate’ in order to use them in other methods. As it is now the code, they return null when I use them. How should I do this?

TransDate dtFromDate,dtToDate;

qbd2 = qbd1.addDataSource(tablenum(assettrans));
qbd2.joinMode(joinmode::InnerJoin);
qbd2.addLink(fieldNum(assettrans,AssetId),fieldNum(assetbook,AssetId));
qbd2.addLink(fieldNum(assettrans,bookid),fieldNum(assetbook,bookid));
qbd2.addRange(fieldnum(AssetTrans, TransDate)).value(SysQuery::range(dtFromDate, dtToDate));

qbd2.addSortField(FieldNum(assettrans, TransDate));

Thanks,

Hey,

Try this code

QueryRun qr;

QueryBuildDataSource qbds;

QueryBuildRange qbr,qbr1;

;

qr = new QueryRun(element);

qbds = element.query().dataSourceTable(tablenum(VendTrans));

qbds.addSortField(fieldnum(VendTrans, Transdate), SortOrder::Ascending);

qbr = qbds.addRange(fieldnum(VendTrans, Transdate));

qbr.value(queryrange(FromDate, ToDate));

qbr2 = qbds.addRange(fieldnum(VendTrans, Dimension));

qbr2.value(BusinessArea);

Where do you store the variables and how do you use them?

Hi,

I want to store ranges in global variables in order to use them. For example in the following job the infolog is empty for 'dtFromDate '.

Is there any way to retreive the value from dtFromDate ?

static void Job119(Args _args)

{

Query q;

QueryRun qr;

QueryBuildDataSource qbd,qbd1,qbd2,qbd3,qbd4;

QueryBuildRange qbr,qbr1;

assettrans tassettrans;

TransDate dtFromDate;

TransDate dtToDate;

q = new Query();

qbd = q.addDataSource(TableNum(assettrans));

qbd.addRange(fieldnum(AssetTrans, TransDate)).value(SysQuery::range(dtFromDate, dtToDate));

qbd.addSortField(FieldNum(assettrans, TransDate));

qr = new QueryRun(q);

If( qr.prompt() )

{

while ( qr.next() )

{

tassettrans = qr.get(tableNum(assettrans));

}

info(strfmt("%1",dtFromDate));

}

}

Thanks,

Your current code doesn’t ever set any value to those variables, so they will be always empty.

You can get values either from parameters, or from internal state of an object. In the latter case, you need to move your code to a class and turn the variables to instance ones (i.e. declared in ClassDeclaration). Then you have to set the values somewhere. If you want to use parameters, move the code to a table method or a class method, turn the variables to parameters and call the method with required values.

whats your actual object in AX, its a Job or report?

and from where you are passing these date values?

Hi,

I made a class for this and I used class SysQuery::FindorCreateRange to retrieve date parameters.

Then I called the class from a button in a form.

Thank you all for your help.