Since day one of using Wappler I confess to being a little unsure of how the server connect Set value component works in relation to names and global names and could not find clarification within forum docs so today I have investigated and these are my conclusions.
Names are of course mandatory, global names are optional parameters
So here is my take on this and my questions about them
We start with
At this point I have always assumed that the difference between the Name and the Global Name were about scope, Name being of local scope, Global being just that, a global variable
So I define a variable in a Set Value stage like this
From this I assume I have defined a local scope variable test which has also global scope when referenced as GtestVar
So now I define a second variable
GtestVar, the global name does not appear in the data picker so has to be referenced by manually entering the name
So variable test, Global Name GtestVar was 6 so tmp will inherit that value of 6 (and it does).
At this time we are still in the same scope so tmp and GtestVar are effectively the same thing
now I add a database query and a repeat
This effectively creates a new name space
so i again add a variable names tmp and assign a value of 5
Now we have two definitions of tmp, the initial definition giving a value of 6 and another within a different scope with the value 5. within the loop the original tmp is in the parent namespace so must be reference as $parent.tmp or it’s global name {{GtestVar}}
(don’t worry if you are getting confused at this point, all will become clear by the end)
So to prove the referencing I now I define an additional variable tmp2 and set it’s value to $parent.test which should be 6
(So if we can reference the parent this way why bother with global names? Simple, with complex actions we could end up with situations like $parent.$parent.$parent.$parent.test. Globals make this so much easier and ensure the correct instance is selected.)
We now define another variable test with value {{GtestVar}}
So now we have a variable at top level
test, global name GtestVar = 6
tmp = GtestVar = 6
in a “lower” namespace we have
tmp = 5
tmp2 = $parent.tmp which should be 6
test = {{GtestVar}} = 6
So i run the query and here is the output as expected with two variables called tmp with different values depending on how they are referenced
So to summarise we can see that those set within the repeat scope assume the values of those in the main parent scope by reference to the Global name or $parent reference however where identical name references occur in different scopes as in “tmp” each instance has its own unique value
If I am correct this is extremely important to understand when dealing with nested actions within Server action or incorrect values may be used due to multiple instances of identically names variables
Have I understood this correctly?
Have I explained this in a way you understand?
Last updated: