I wrote the following job - to learn more about how AX and X++ work, but it is driving me crazy.
It is having problems with this line below: qbr2 = qbds1.addRange(fieldNum(dimensionAttributeValueSetItem,DisplayValue));
When I run it, it gives a critical stop and says: Invalid range. It is a valid field in DimensionAttributeValueSetItem, but for some reason it doesn't think so.
I have been over my program multiple times and cannot find any error - what would make it give an error like that? What am I missing?
static void DantestInventTable(Args _args)
//Define Query
{
Query query;
QueryRun queryRun;
QueryBuildDataSource qbds1;
QueryBuildDataSource qbds2;
QueryBuildRange qbr1;
QueryBuildRange qbr2;
InventTable inventTable;
DimensionAttributeValueSetItem dimensionAttributeValueSetItem;
Struct structOutput;
structOutput = new struct
("str ItemTableID;"
+ "str DisplayValue;"
);
//the Build
query = new Query();
qbds1 = query.addDataSource(TableNum(InventTable));
qbds1.addSortField(fieldNum(InventTable,ItemId));
qbr1 = qbds1.addRange(fieldNum(inventTable,SemRevenueType));
qbr1.value("Essential 08-01");
qbr2 = qbds1.addRange(fieldNum(dimensionAttributeValueSetItem,DisplayValue));
qbr2.value("P25");
qbds2 = qbds1.addDataSource(TableNum(DimensionAttributeValueSetItem));
qbds2.relations(false);
qbds2.joinMode(joinmode::ExistsJoin);
qbds2.addLink(fieldnum(InventTable,DefaultDimension),fieldnum(DimensionAttributeValueSetItem,DimensionAttributeValueSet));
//the Instantiation
queryRun = new queryRun(query);
//the Action
// the If condition checks to see that the query is running. If not, it will not execute.
if (queryRun.prompt())
{
//the while loops over the InventTable in search of the information needed.
while (queryRun.next())
{
inventTable = queryRun.get(tableNum(InventTable));
dimensionAttributeValueSetItem = queryRun.get(tableNum(DimensionAttributeValueSetItem));
structOutput.value("ItemTableID",inventTable.ItemId);
structOutput.value("DisplayValue",dimensionAttributeValueSetItem.DisplayValue);
info(structOutput.toString());
}
}
*This post is locked for comments