0

How to assign a table's identifier to a variable, i.e. not hardcode table names in functions?

The openTable("table", "view") function uses strings as parameters. This is great as you can read a table name from anywhere (e.g. a field value), e.g. let t := 'Field storing table name string' and then use that variable in an openTable(t, "view") function. The problem is openTable seems to be the only function that accepts the table identifier as a string, e.g openRecord(record(table, id)) the table is not a string but an identifier. If you try to use a string you get an undefined function error and the script won't save. So what's the solution? I'm guessing that changing all the other functions to also accept strings is unlikely. Is it possible to cast a string into an identifier or lookup an identifier using a string of the tables name or id? I want to be able to use openRecord() from a dashboard but don't want to hardcode the table name as I have too many and they are not all related. 

4 replies

null
    • Sean
    • 4 yrs ago
    • Reported - view

    This might be too close to hardcoding, but it's the only solution that I know of. Personally, I would use a Choice field, but it would also work for a Text field if you like to type everything in. Use a switch statement in "Trigger after update" of the field type you choose to execute the openRecord() function. Yes, you are hardcoding the table names, but once it's done you'll only have modify it when you add or remove tables.

    • Alec
    • 4 yrs ago
    • Reported - view

    Thanks, Sean, I had already worked out the switch statement. I was hoping there was an alternative as it's rather cumbersome. The text field is better for my scenario as the field is hidden with data populated programmatically, so typos wouldn't be an issue (unless I code it badly) and I don't need to map Choice Ids to Table names anywhere in code or otherwise.   

    • Sean
    • 4 yrs ago
    • Reported - view

    I don't have a solution, but I am curious. In your dashboard would you enter the table name and record number in a single text field if that would work?

    • Alec
    • 4 yrs ago
    • Reported - view

    Could do but would see little advantage over separate fields, unless you have a cunning plan?

Content aside

  • 4 yrs agoLast active
  • 4Replies
  • 1670Views