Also, is there a way to use the IMPORT function in the onValue script field?
There is not, flexible programmatic file loading would be best handled using a custom module.
I realize that a custom module would be best. Yet I found this (ugly) solution works for me to have a single piece of code used by 160 different buttons:
Wait, I thought you were looking for a js equivalent to IMPORT{} that could be called in a script. You can write IMPORT{} in onValue in order to define the content of the script using an external file.
My appologies for not being clear. What I would like is both reusing script code (by using an external file) and some flexibility in onValue. Ideally some combination like this:
onValue:
< here some directly written code >
< and here a call to import an external .json file >
< and here a call to another external .json file>
< here some more directly written code >
< etc. >
What is the exact syntax for using the IMPORT{} function in onValue?
Just writing IMPORT{/scripts/buttonCode.json} or JS{IMPORT{/scripts/buttonCode.json}} doesn't work I had noticed.
Sorry, I overlooked your code and thought you were attempting to import a script (js file) to be executed, not a json file to be consumed. I think the cleanest way would be to use variable widgets with IMPORT{} statements in their value property (one per variable widget) and then retrieve the json data with a simple get('variable_widget_id').