question

martin.j avatar image
1 Like"
martin.j asked Phil BoBo edited

Table.getValueByKey returns exception when no value can be found

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?

FlexSim 20.0.1
exception errortable commandstable queriesgetvaluebykeyi think the errors may be due to the incorrect referencing of label in the value field for the columns
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

·
Phil BoBo avatar image
2 Likes"
Phil BoBo answered Phil BoBo edited

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);
5 |100000

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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