Global Variables vs Passing By Argument

I am fairly new to UIPath and have a question about Project architecture.

In other languages and platforms, I scope variables at the lowest level I can and use global variables sparingly. However, not having global variables in UIPath is very annoying. There are some variables that might be used in many different modules, and I don’t want to pass them through a bunch of arguments. I have used the Getter Setter activity in order to do this.

My coworker, who has written many more projects than I have, thinks that the use case for global variables is much more limited than I think and I have gone overboard. He says that UIPath thinks using arguments is superior to global variables, as they will be overused. Maybe I am so used to using global variables that it is hard for me to see the benefit of doing it the UIWay.

I am very curious about the communities opinion.

1 Like

Arguments are usually a better practice since the path from setting the argument to using it is more concrete so investigating where the value was changed can be easier to track. Using global variables means that you need to check each and every workflow to track changes to values.

If you insist on using global variables you can use the System.Environment class which provides access to such global variables in a dictionary format through the methods: GetEnvironmentVariable and SetEnvironmentVariable. For more information you can check the official documentation from Microsoft here: Environment Class (System) | Microsoft Learn

1 Like

For global variables you can use the Velocistar Global Variables Activities now!
These are available everywhere in your robot without using arguments.