Query through X++

static void Query(Args _args)
{
Query query;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
QueryRun qr;
CustTable custTable;
CustTrans custTrans;
;
//Creating a query object
query = new Query();

//Adding datasource
qbds = query.addDataSource(tableNum(CustTable));

//Adding range to query
qbr = qbds.addRange(fieldNum(CustTable,CustGroup));

//Adding range value
qbr.value(queryValue(30));

//Adding Enum as range
qbr.value(QueryValue(Enum::element1));

//Adding another datasource
qbds = qbds.addDataSource(tableNum(CustTrans));

//Relation between two datasources
qbds.relations(true);

//Underlying Query
info(query.dataSourceNo(1).toString());

//Creating a QueryRun object
qr = new QueryRun(query);

while(qr.next())
{
custTable = qr.get(tableNum(CustTable));
custTrans = qr.get(tableNum(CustTrans));
info(strfmt("%1--%2",custTable.AccountNum,custTrans.AmountMST));
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s