Monday, January 11, 2010

Use FIELD in pages to declare global variables

Edit: It only seems to work when the page is set to Content-Type: Notes, which is a drag (needed it for a custom content-type/JS-page)..

What I've probably longed most for in pages is the ability to have global variables. I thought this was impossible due to the lack of fields in a page.

It turns out it's quite simple. The reason I came up with trying this is Andre Guirards article on Using View Column Programmatic Names. In this article (recommended read!), he discusses the usage of FIELD in view columns/selection formulas to create temporary global variables.

To declare a variable as global, put FIELD in front of it.
FIELD globalVariable := "I'm global!";
For cross client (Notes/Web) pages, it seems that you have to put the global variable declarations in "Window Title". First declare your variables using FIELD, then add the code for the window title.

Declaration:


Using the variable in a computed text:


Notes:


Web:

3 comments:

Dwight Wilbanks said...

Very good find! I don't know when, but, I suspect I will be using that one at some point in the future.

Thanks

Tommy Valand said...

No problem.. :)

This is probably most useful when you want to use the result of a dblookup/dbcolumn multiple places, or have global constants (replicaid/db path/etc.).

At least that was what I planned using it for.

Anonymous said...

Thanks a lot... this saved me a lot of coding as well as waiting time to ReCache dbcolumns for every computed field... Thanks