I am attempting to change a variable I created in a block using JS code. Unfortunately, the changes made in the code do not reflect in the variable after running the program. The code has been verified in VS Code to run properly and to the spec as needed.
Additionally, the global variable declaration and subsequent code is very similar to behavior in another bot that DOES work.
Finally, by adding a bit to the code that throws an error if the variable is properly updated within the context of the code, I am able to verify that until the bot exits the JS Code block, the variable is properly updated, and then it reverts to the initial state as if it were a local variable deleted when it goes out of scope.
Edit: This topic is resolved, turns out throwing an error causes the platform to dump any changes to global variables made in the JS block. This should be described in the documentation for the “Execute JS code” function
I’ve just clarified the question within our technical team. It’s not a bug and let me explain why. We are waiting for a block to completely finish its action. If there are no errors during the execution of this block, then the information (hence, variables) are updated. If there is an error then there are no updates and the error message appears.
In your case you can solve it in two different ways.
First of all, you can split one “Execute js code” block to two blocks. The first one will update the variables and the second one will throw an error in case of something.
Or you may use a sort of boolean flags technique and reorganize errors handling approach in your bot. I can’t help you with more details on this method because I need to know the details of your code. But I think if you understand the reason why it happened (explained above) you’ll be able to find a proper solution for that.