Library APIs ignore the Global setting of a variable

It looks like the string.replace() function, if used inside a Library API, does not respect the Global name of a variable. This problem may happen with other functions, but I only tested with “string.replace()”.

I created a short piece of code to reproduce this problem, and I observed the same behaviour using NodeJS and PHP server modes.

I am running Wappler 5.2.2 using Windows 10.


Here’s an example code that runs fine when used as a “normal” server action:

In steps that set the value of the variable myString, the Global Name is also set to “myString”.

And this is the result:

As you can see, at the end of the repeat, all tokens have been replaced.


If I create an API Library using the same steps as before and execute it from a normal API, the result is not what one would expect:

Effectively, each iteration of the repeat loop seems to have its own local version of myString, completely ignoring the Global setting and at the end, myString is not altered.

If this is not a bug but rather the intended behaviour of a Library API (it would be odd, but I don’t know), can you please guide me on how to address this problem?

Many thanks!

I upgraded from 5.2.2 to 5.2.4 because I read that this problem
Variables with Global Names Stopped Updating in Library Actions, which looks similar to the one I reported, had been fixed in 5.2.4.

I just wanted to let you know that unfortunately, the problem that I reported still occurs in Wappler 5.2.4.

Thank you in advance for your prompt attention.


Also linked

What happens when you change the name of the setvalue action in the repeat, call it myStringInner and the global name myString.

Just to clarify, the Name of a variable is the local variable name, it is created within the current scope. The Global Name is the global variable name, it is being set on the global scope. When using a variable within an expression it will first look in the local scope and then go up the scopes up to the global scope until it finds a variable with that name.

For the exec action it creates a sub scope when you give it a name, you can see this as it creates a sub object in the output. The initial myString is a local variable in that sub scope and you set with the Global Name the global variable, but in the same time you set a local variable with the same name. In the After step it will return the local myString variable since it is the first one it finds and not the global.

Thx Patrick for your response, but I’m still observing a weird behaviour after doing the following:

In the API:
Named the local variable myString_API (Global Name: myString_API)

In the LIB:
Named the local variable myString_LIB (Global Name: myString_LIB)

There is no possible name conflict between the code in the API and the code in the Library.

The code in the API now looks like this:

And the code in the library looks like this:

To be clear, there are no parameters passed to the library and none of its outputs is consumed by the API. What you see below is inside the API and inside the Library.

When running the API, which as a last step invokes the library, the output looks like this:

Note the differences in the underlined text, showing that the API preserves the changes done by the previous step in the repeat (in green) while the LIB (in red) does not.

I hope this helps a bit more.

Just to be certain: the output that I see from the library is not what I should see, right? I am expecting to see a behaviour similar to that of the API…

Many thanks!


I also tried what you said in the other post: name the variable within the repeat differently, while preserving its Global value. The result was the same:

Hi @patrick ,
Do you have a date to fix this? I’m eagerly waiting :slight_smile:
Also, please let me know if there is anything I can do to further clarify.

Many thanks!