How to get a table reference in a script
Ninox Profile

I would like to use popupRecord() to open a record in an unrelated table. This is fine if the table name is known in the record() function, e.g. popupRecord(record(SomeTable,Id)) works when SomeTable already exists and your script only wants to open records in SomeTable. I have lots of unrelated tables and want to be able to open a record in any of them based on data in the currently open table. E.g in the current table I have 2 fields UnrelatedTableName and UnrelatedID, how can I use these values to construct record(UnrelatedTableName,UnrelatedID) at runtime. The script editor complains that UnrelatedTableName is not a table. Is there a way to cast a string into a table name at runtime? Alternatively, can I construct a string and then execute the string (similar to the API script execution)? The only workaround I have is a switch case for every table I have e.g.

switch UnrelatedTableName do 
case "SomeTable1": popupRecord(record(SomeTable1,UnrelatedID))
case "SomeTable2": popupRecord(record(SomeTable2,UnrelatedID))
end

Would be so much cleaner and easier to maintain if there was something like;

let t := tableRef(UnrelatedTableName);
popupRecord(record(t,UnrelatedID))

or;

let scriptString := "popupRecord(record(" + UnrelatedTableName + "," + UnrelatedID + "))";
executeString(scriptString)

Can't find either of these approaches in the docs or forum. Do either/both exist? Thanks.

Reply