Error message "controller is not defined"

I have 85 value lists that are used in about 40 forms. I use setValueListItems to query the data from a SQL database and polulate each value list. The value lists used in each form are populated using a method that is triggered by the form’s OnLoad event. This approach works fine, but results in code duplication and unnecessary processing, since the same value lists are used in multiple forms.

I’d like to consolidate the value list code from all forms into a single global method that runs when the Solution loads. I’ve tried this but get the error message “controller is not defined” when running the code as a global method. The code is exactly the same as in the form methods, compliles fine as a global method, but will not run as a global method.

I haven’t been able to find anything related to this on the forum or in the documentation.

Thanks for your help.

what are your valuelists based on?

relationships, foundsets or custom queries?

when do you set the valuelists? on startup of the application, onLoad of a form?

the solution startup method can’t access any controller.
There is no form yet so there can’t be a controller.

but why do you need a controller for filling value lists?

Of course you can do this with the onload of the first form you encounter. (do there all the things you want)

Here’s a way a global script would look like, being triggered in a startup script:
(notice that there’s no reference to any forms, as they aren’t reachable yet during startup)

var query = "select col1, col2 from table...etc";
var dataset = databaseManager.getDataSetByQuery('serverName', query, null, 100);
var displayValue = dataset.getColumnAsArray(1)
var returnValue =  dataset.getColumnAsArray(2)
application.setValueListItems('myValuelistName',displayValue,returnValue);

Thanks Maarten. It looks like this will do the trick.