How to give a variable scope for the whole page?

I created some variables within a page’s On Page Enter logic.
In this step the variables get assigned values - the default values for when the page is loaded.

vars-a-b-c

I would like to access those same variables in an input element’s On Change Event logic.
The idea is that at this step the values can be modified.

vars-empty

But as can be seen from the second screenshot, varA, varB, and varC have disappeared from the menu.

Is there some way to access them?

Thanks for any guidance on this.

Hi, @Causality

If you define a variable, it has scope. So, when you create two variables with the same name in different handlers, these are two completely different variables.

To access some data in an input element from On Page Enter logic you can put it into the Page Data.

Regards,
Serhiy

Hello @Serhiy_Melnychuk,

Thank you for the reply. Sorry I didn’t get back to you sooner.
I think I basically understand now, after playing around with the available blocks a little more.


I am starting to like this way of organization:

Set (or retrieve from the database) the property value On Page Enter

Above: Properties varA, varB, varC being “declared” and assigned initial values when the page is loaded.

Okay, maybe varA, etc. is a confusing naming convention for properties.
Sorry, I’m not going to redo the screenshots. Just pretend I did better. :wink:

Within a handler, assign the values from the properties to variables

Above: Variables a, b, c being assigned the values from properties varA, varB, varC.

Once this is done, any kind of operation can be performed on the variables without having to Get Property and Set Property at each step. It makes the “code” (the logic blocks) a lot cleaner looking.

Once the magical manipulation is done, transfer the values from the variables back to the properties.

03-set-property-in

They can now be accessed by other handlers in subsequent steps.


Well, it feels like a start.

Functions

Now I have a new question - what about the scope of functions?
Is there a way to make a function global?
(These too appear to be locally confined to their present handler. I have been pasting them a lot.)

Hi, @Causality

To make a function global, you should use Custom Functions (the ones located next to Handlers).

Regards,
Serhiy

Thank you! I understand now.

For anyone else trying this for the first time, I recommend watching this tutorial video:
Custom Functions (logic reuse)

1 Like