Table.getValueByKey returns exception when no value can be found

Table.getValueByKey returns exception when no value can be found

MBJEBZSRG
Advocate Advocate
359 Views
1 Reply
Message 1 of 2

Table.getValueByKey returns exception when no value can be found

MBJEBZSRG
Advocate
Advocate

[ FlexSim 20.0.1 ]

I am using the getValueByKey() to look up information in a bundle table, but there are situations where key I look up simply is not in the table, and that is ok - I can go on from there. Unfortunately the method throws an exception and quits the script or activity it is in with unpredictable behavior to follow.

exception: FlexScript exception: no row found for key 5 in col 1 at <no path> c: <no path> i: <no path>

Is there a way to catch this exception or have the method simply return NULL if no matching result is found?

Reply (1)
Message 2 of 2

philboboADSK
Autodesk
Autodesk
Accepted solution

If you don't know whether the key is in the table, use table.getRowByKey() instead of table.getValueByKey():

Table table = Table("GlobalTable1");
int key = 5;
int valueCol = 2;

int row = table.getRowByKey(key);
if (row)
	return table[row][valueCol];
else
	return 0; // handle what to do if the key isn't in the table

//return table.getValueByKey(key, valueCol);


Phil BoBo
Sr. Manager, Software Development