question

justinrusty avatar image
0 Likes"
justinrusty asked Jordan Johnson answered

Table.query invalid row

I have been attempting a user event that essentially checks a global list of items that is continuously updated. This list of items is then transfered into variables and converted using multipliers so that I can better understand inventory in the form of pallets over time.

The event code is as follows

/**Custom Code*/

Object current = ownerobject(c);

double ItemPallets;

double Total_Pallets = 0;

int Pallet_Item = 1;

double NumRows = Table("WarehouseInv").numRows;


while (Pallet_Item <= NumRows) {


string strItemVal = "SELECT Quantity FROM GlobalWarehouseInv WHERE MatlName = Item " + numtostring(Pallet_Item);


string strItemTemp = "SELECT Temp FROM GlobalWarehouseInv WHERE MatlName = Item " + numtostring(Pallet_Item);


string strItemSize = "SELECT Size FROM GlobalWarehouseInv WHERE MatlName = Item " + numtostring(Pallet_Item);


//query returns a Table. Here we expect a single value in the table.


Table I = Table.query(strItemVal);

Table T = Table.query(strItemTemp);

Table S = Table.query(strItemSize);


double NumItem = I[1][1];

double ItemTemp = T[1][1];

string Size = S[1][1];

if (Size == "S")

{ItemPallets = NumItem*0.2;}

else if (Size == "M")

{ItemPallets = NumItem*0.4;}

else

{ItemPallets = NumItem*0.6;}


Total_Pallets = Total_Pallets + ItemPallets;

Pallet_Item = Pallet_Item + 1;

}


I keep recieving the following error however: time: 5.000000 exception: FlexScript exception: Invalid row number: 1 in Table.query() result table. at MODEL:/Tools/UserEvents/CalcPallets>variables/event



FlexSim 22.2.2
queryevents
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered

Since you have a WHERE statement in your queries, it is entirely possible that no rows match the query. At time 5, apparently, there are no rows in the result table. However, you are using the syntax SomeTable[1][1], which assumes that a row is present. The error message is saying the row is not present.

Consider using code like this:

double numItem = 0;
if (I.numRows == 1) {
  numItem = I[1][1];
}
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.