Global integer variable to be exchanged / incremented via different scripts in XML

Hi,
How can I define and use a global INTEGER variable to be exchanged with other scripts / verified by condition (if-then-else) and incremented in XML for a loop run (not via recording)?
This should be a separate variable than the loop index.
Thanks for hints.

1 Like

Hi,

Could you give more detail on your problems?
Are the scripts located within the same file or not ?
If so, you can use sys.defineVariable / sys.getVar() (https://kb.workfusion.com/display/WF/Bot+Tasks+Context)
If not, I would recommand creating a class to store/modify this integer in one script, and create static setter/accessor methods to interact with it from other scripts

1 Like

HI, thank you for some hints. What I would like to do is to define 2 “counters” - “c” - for Country_details and “l” for Location name (both starts from 0) and harvest few fields from WWW. There are one to many relation between country and location (c & l), then I want o harvest data in the loop increasing +1 (c & l) till IF will show the combination is empty and THEN increase “c” by 1 and make “l” zero again, and so on… (so the combination would be: c & l: 0,0; 0,1;0,2;0,3 (assume last location for c=0 is l =2, then IF will show 0,3 empty and Then will switch c=1, l=0 and again c & l: 1,0; 1,1; 1,2 …)

All is in one bot (XML file) but across CDATA, loop, IF-THEN - so I would like to exchange counters c & l between these part of code.
Thanks again, Andrzej

1 Like

Ok so you should define your two counters using
sys.defineVariable(YourCounterName,yourCounterDefaultValue)
sys.defineVariable(YourCounterName2,yourCounterDefaultValue2)
in your first Cdata

Now at the start of each Cdata you can do:
counter1 = Integer.parserInt(sys.getVar(YourCounterName).toString()) to get the counter value
careful, getVar returns a webHarvest object that you want to unwrap. What I find easier is to get the string and directly convert it to what you want - in your case integer-

At the end of each Cdata save the value using
sys.defineVariable(YourCounterName,counter1 )

This should do the trick :slight_smile:

1 Like