Hi people, I have a problem and need your help. I have to filter the InventTable by one of 3 conditions, but whatever the condition I have to run all records with an instruction ‘while’. At this moment i do this code. inventTable.clear(); if (param == 0) { select * from inventTable where inventTable.ItemId == itemId; } if (param == 1) { select * from inventTable where inventTable.SCHQ_Process == true; } if (param == 2) { select * from inventTable; } while (inventTable) { info(strfmt(“ItemId - %1”,inventTable.ItemID)); } The problem is that it make loop someone can help me?
You can successfully use the query/queryrun framework instead of select/while select.
The problem is that you have :
while (inventTable){
//------------
}
This makes a loop [:D]
Try this:
static void Job1(Args _args)
{
InventTable inventTable;
Query qr;
QueryRun qrRun;
QueryBuildDatasource qbds;
QueryBuildRange qbr;
int parm = 2;
ItemId itemId;
ItemGroupId itemGroupId;
;
itemId = “CN-01”;
itemGroupId = “Parts”;
qr = new Query();
qbds = qr.addDataSource(tablenum(InventTable));
switch(parm){
case 1:
qbr = qbds.addRange(fieldnum(InventTable, ItemId));
qbr.value(itemId);
break;
case 2:
//select * from inventTable where inventTable.SCHQ_Process == true; → i use a different field
qbr = qbds.addRange(fieldnum(InventTable, ItemGroupId));
qbr.value(itemGroupId);
break;
case 3:
//no range
break;
default:
break;
}
qrRun = new QueryRun(qr);
while(qrRun.next()){
inventTable = qrRun.get(tablenum(InventTable));
info(strFmt(“Item %1”, inventTable.ItemId));
}
}
Hope this help
Thanks… works