Global variables

Is it possible to keep (use) Kantu global variables even the program restarts Kantu?

Global vars get deleted once Kantu closes. But you can “rescue” the values by storing them inside a CSV file:

If you want your data to survive a closing of Kantu, then store (“persist”) it in a CSV file withcsvSave and csvRead:

1 Like

Thank You :slight_smile:

@admin, any plans to bring persistent global variables? Creating/modifying code to read/save a CSV file every time I want a global persistent variable causes unnecessary friction.

Or is there any solution to mass-dump/mass-read all global variables to/from a CSV file without hard-coding their names?

every time I want a global persistent variable

A good solution here is to use move your “global variable saving” code snippet into a subroutine (“sub-macro”) with the Selenium IDE-style RUN command. Then you can reuse it in every of your macros!

mass-dump/mass-read all global variables

Do you mean variables that survive even the closing of UI Vision? No programming or scripting language has such a feature, and so we have no plans to introduce it.

How many variables do you have? If it is a lot, maybe using an array is maybe more effective. Meanwhile the RPA software also has csvSaveArray and csvReadArray.

Hi,

Thanks for your answer. Perhaps a better solution for this would be the ability to save/load JSON objects, that way I could create my variables inside a JSON object and save/load from a file. May I suggest two commands?

  • readJson
  • saveJson

An array wouldn’t allow me to create named-variables, that’s the issue.

In my opinion you solve all your problem creating a good macro code, there is not any reason to create complex macro code.

Remember good coder create simple, fast and efficient macro code, more simple code less error and bugs.

I automate every site and i use always simple macro code to have short code, maximum speed and few bugs

In my life I never used global variables because there are more alternative to not use it, you can use a master csv with all data, you can use an array with all values, you can use a sub macro to load the var (store XXX var1) and other similar solutions.

Hi,

I understand that, I’m doing this:

  1. Load variables from CSV file (sub-macro)
  2. Do my macro stuff
  3. Save variables to CSV file (sub-macro)

So, no need for an actual “global” variable, though the point is saving/reading variables to a file is easier in Python than it is in UI.Vision, I don’t want to play with array indexes.

There are cases where it makes more sense to store data in a JSON file than CSV (otherwise, who would use JSON at all?). But anyway, I could probably achieve this with JSON.stringify and use saveCsv now that I think about it.

I don’t understand why you don’t load variables directly into the macro code it’s very simple, you can use the “store” command, if you need it in multiple macros you can copy the commands to various macros so it’s all very simple. Or you can create a macro with all the saved variables (store - value - var1) and run it with the “run” command inside the main macro.

I also use variables within macros and simply impose them all at the beginning of macros, so they are loaded immediately or I create a csv with all the data and use them with the !Col1.