# Setting form name in global issue

**URL:** <https://forum.servoy.com/t/setting-form-name-in-global-issue/3826>\
**Category:** Classic Servoy\
**Created:** [March 9, 2005, 9:36am UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826 "2005-03-09T09:36:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmad](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ahmad](https://forum.servoy.com/u/ahmad)\
**Post date:** [March 9, 2005, 9:36am UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/1 "2005-03-09T09:36:27Z")

</div>

Hi,

I set a form name in a global field (in start up) so that it could be used all over..

globals.mainForm = forms.main;

I set the global value in a variable another method as  
var mainForm = globals.mainForm ;

var btnName = “something”;

// When I tried to get the btnObj as

var btnObj = mainForm.elements[btnName];

I get an error.. The undefined value has no property. The same thing work if I directly set  
var mainForm = forms.main;

I think something wrong. Could you please check

Thanks

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [March 9, 2005, 10:33am UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/2 "2005-03-09T10:33:41Z")

</div>

What type is globals.mainForm?  
If you want to store the object you need to make it a media global.

---

<div class="post-metadata">

**Author:** ![ahmad](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ahmad](https://forum.servoy.com/u/ahmad)\
**Post date:** [March 9, 2005, 10:40am UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/3 "2005-03-09T10:40:06Z")

</div>

> ROCLASI:  
> What type is globals.mainForm?  
> If you want to store the object you need to make it a media global.

It’s not an actual field created in dataproviders

It’s a runtime global variable

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [March 9, 2005, 11:58am UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/4 "2005-03-09T11:58:55Z")

</div>

globals.mainForm is a global variable that you have set in the dataproviders right ? (I know it’s not a table column).

So what is the media-type of this global ?

---

<div class="post-metadata">

**Author:** ![ahmad](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ahmad](https://forum.servoy.com/u/ahmad)\
**Post date:** [March 9, 2005, 12:15pm UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/5 "2005-03-09T12:15:11Z")

</div>

> ROCLASI:  
> globals.mainForm is a global variable that you have set in the dataproviders right ? (I know it’s not a table column).
> 
> So what is the media-type of this global ?

It’s not at all a field created in the design mode under dataproviders tab. It’s just a javascript global variable used within the method.

I think you know Servoy allows to declare a javascript variable as global.

for eg: you can in your method you can declare as

globals.anyName = “anything”

This value could be used in anyscript until the solution is closed

Thanks

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [March 9, 2005, 12:53pm UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/6 "2005-03-09T12:53:17Z")

</div>

> ahmad:
> 
> > ROCLASI:  
> > globals.mainForm is a global variable that you have set in the dataproviders right ? (I know it’s not a table column).
> > 
> > So what is the media-type of this global ?
> 
> It’s not at all a field created in the design mode under dataproviders tab. It’s just a javascript global variable used within the method.
> 
> I think you know Servoy allows to declare a javascript variable as global.
> 
> for eg: you can in your method you can declare as
> 
> globals.anyName = “anything”
> 
> This value could be used in anyscript until the solution is closed
> 
> Thanks

I see why we didn’t understand each other at first.  
As far as I know _globals_ is a Servoy class.  
I know you can define global javascript variables by not using **var** when assigning a variable a value for the first time.  
But you are using globals.mainForm = forms.main;.  
Instead you should use mainForm = forms.main;

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [March 9, 2005, 1:24pm UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/7 "2005-03-09T13:24:36Z")

</div>

No, Ahmad is right here.

Declaring global JavaScript variables by not putting var in front of the declaration created a global variable, but, according to the manual, the prefered way by Servoy is declaring it like globals.xxxx = value;

I think there is not much difference between the two and how the global variable is declared is probably not why Ahmad’s method isn’t working.

But, probably, it’s a clash of classes, in that a global cannot containt an form reference.

Paul

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [March 9, 2005, 2:09pm UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/8 "2005-03-09T14:09:33Z")

</div>

> pbakker:  
> Declaring global JavaScript variables by not putting var in front of the declaration created a global variable, but, according to the manual, the prefered way by Servoy is declaring it like globals.xxxx = value;

I guess I should read the manual for once then ![;)]( "Wink")

Anyway, I did some testing and indeed you can’t assign a form object to a globals.xxx variable.  
Without the prefix _globals._ however it does work.

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [March 9, 2005, 2:15pm UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/9 "2005-03-09T14:15:26Z")

</div>

Why read manuals?!?! We’ll tell you ![:D]( "Very Happy")

---

<div class="post-metadata">

**Author:** ![ahmad](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ahmad](https://forum.servoy.com/u/ahmad)\
**Post date:** [March 11, 2005, 6:11am UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/10 "2005-03-11T06:11:49Z")

</div>

> pbakker:  
> probably, it’s a clash of classes, in that a global cannot containt an form reference.

Can this be fixed by Servoy people..please.. ![:(]( "Sad")

because I’m puttting all my common methods in a module which needs to access some forms which is set in globals

Thanks in advance

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [March 11, 2005, 1:05pm UTC](https://forum.servoy.com/t/setting-form-name-in-global-issue/3826/11 "2005-03-11T13:05:06Z")

</div>

Ahmad,

Like I said after my test, it works with global javascript variables as long as you don’t use the prefix _globals._

Hope this helps.
