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.
WHAT WORKS FINE
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.
WHAT DOES NOT WORK
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?