# Error message "controller is not defined"

**URL:** <https://forum.servoy.com/t/error-message-controller-is-not-defined/2200>\
**Category:** Classic Servoy\
**Created:** [July 8, 2004, 9:49pm UTC](https://forum.servoy.com/t/error-message-controller-is-not-defined/2200 "2004-07-08T21:49:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Jackson](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@Robert\_Jackson](https://forum.servoy.com/u/Robert_Jackson)\
**Post date:** [July 8, 2004, 9:49pm UTC](https://forum.servoy.com/t/error-message-controller-is-not-defined/2200/1 "2004-07-08T21:49:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [July 8, 2004, 10:43pm UTC](https://forum.servoy.com/t/error-message-controller-is-not-defined/2200/2 "2004-07-08T22:43:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [July 9, 2004, 11:12am UTC](https://forum.servoy.com/t/error-message-controller-is-not-defined/2200/3 "2004-07-09T11:12:18Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forum.servoy.com/u/maarten)\
**Post date:** [July 9, 2004, 1:46pm UTC](https://forum.servoy.com/t/error-message-controller-is-not-defined/2200/4 "2004-07-09T13:46:53Z")

</div>

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)

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![Robert\_Jackson](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@Robert\_Jackson](https://forum.servoy.com/u/Robert_Jackson)\
**Post date:** [July 14, 2004, 1:08pm UTC](https://forum.servoy.com/t/error-message-controller-is-not-defined/2200/5 "2004-07-14T13:08:56Z")

</div>

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