Table.query invalid row

Table.query invalid row

justin.watkins54DXV
Participant Participant
214 Views
1 Reply
Message 1 of 2

Table.query invalid row

justin.watkins54DXV
Participant
Participant

[ FlexSim 22.2.2 ]

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



0 Likes
Accepted solutions (1)
215 Views
1 Reply
Reply (1)
Message 2 of 2

JordanLJohnson
Autodesk
Autodesk
Accepted solution

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];
}
.


Jordan Johnson
Principal Software Engineer
>

0 Likes