Multiple variables at once

Discuss RoboTask here
Post Reply
Rukbunker
Posts: 192
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Multiple variables at once

Post by Rukbunker »

Hey Oleg,

There are similar topics here which all partly answer my question, hence this specific topic.
We have a task coming up (as a pilot) which should declare some variables at once. The input is a CSV (or similar). For every line in the CSV, Robotask should do something. (Yes, the loop comes in here ;))

The CSV looks like:

Code: Select all

Customernumber,CustomerName,Mail
000001,Robotask,info@dummymail.hay
000052,YankyDoodle,dontwrite@mail.co.uk.br.tr
With every loop, I want to declare the values per line all at once to different variables.

What is your best approach?
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Multiple variables at once

Post by Oleg »

Look at examples below

The simplest way to set each element to separate variable from comma-separate string

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1163085779
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1416"
Hide=INTEGER|0
ID=INTEGER|-369271517
LogOnAsUser=INTEGER|1
Name=STRING|"Set variables from list"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|2
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=FOLDER
Action16=FOLDER
Action17=FOLDER
Action18=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""list"" (source text)"
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"list"
varvalue=STRING|"Customernumber,CustomerName,Mail{EOL}000001,Robotask,info@dummymail.hay{EOL}000052,YankyDoodle,dontwrite@mail.co.uk.br.tr"

[Actions\Action10]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CustomerNum"" with value ""{Line(0)}"""
Params=FOLDER

[Actions\Action10\Params]
expand=STRING|"1"
varname=STRING|"CustomerNum"
varvalue=STRING|"{Line(0)}"

[Actions\Action11]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CustomerName"" with value ""{Line(1)}"""
Params=FOLDER

[Actions\Action11\Params]
expand=STRING|"1"
varname=STRING|"CustomerName"
varvalue=STRING|"{Line(1)}"

[Actions\Action12]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""mail"" with value ""{Line(2)}"""
Params=FOLDER

[Actions\Action12\Params]
expand=STRING|"1"
varname=STRING|"mail"
varvalue=STRING|"{Line(2)}"

[Actions\Action13]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//output variables"
Params=FOLDER

[Actions\Action13\Params]
comment=STRING|"output variables"

[Actions\Action14]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action14\Params]
message=STRING|"line = {Line}"
type=STRING|"3"

[Actions\Action15]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action15\Params]
message=STRING|"{CustomerNum}"
type=STRING|"3"

[Actions\Action16]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action16\Params]
message=STRING|"{CustomerName}"
type=STRING|"3"

[Actions\Action17]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action17\Params]
message=STRING|"{Mail}"
type=STRING|"3"

[Actions\Action18]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""first"" with value ""true"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varname=STRING|"first"
varvalue=STRING|"true"

[Actions\Action3]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action3\Params]
message=STRING|"****************"
type=STRING|"3"

[Actions\Action4]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action4\Params]
destvar=STRING|"LINE"
line0=STRING|"{list}"
linecount=STRING|"1"
sourcetext=STRING|"1"

[Actions\Action5]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then //skip 1-st line"
Params=FOLDER

[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{first}"

[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""first"" with value ""false"""
Params=FOLDER

[Actions\Action6\Params]
expand=STRING|"0"
varname=STRING|"first"
varvalue=STRING|"false"

[Actions\Action7]
ActionID=STRING|"A_LOOP_CONTINUE"
Enabled=INTEGER|-1
Name=STRING|"Continue"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action9]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//set variables"
Params=FOLDER

[Actions\Action9\Params]
comment=STRING|"set variables"
This example stores each line as JSON object. JSOM is preferred if you use for more complex structures or arrays

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1163085779
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1417"
Hide=INTEGER|0
ID=INTEGER|1343852539
LogOnAsUser=INTEGER|1
Name=STRING|"Set variables from list (json)"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|2
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=FOLDER
Action16=FOLDER
Action17=FOLDER
Action18=FOLDER
Action19=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""list"" (source text)"
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"list"
varvalue=STRING|"Customernumber,CustomerName,Mail{EOL}000001,Robotask,info@dummymail.hay{EOL}000052,YankyDoodle,dontwrite@mail.co.uk.br.tr"

[Actions\Action10]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""json:Customer.Number"" with value ""{Line(0)}"""
Params=FOLDER

[Actions\Action10\Params]
expand=STRING|"1"
varname=STRING|"json:Customer.Number"
varvalue=STRING|"{Line(0)}"

[Actions\Action11]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""json:Customer.Name"" with value ""{Line(1)}"""
Params=FOLDER

[Actions\Action11\Params]
expand=STRING|"1"
varname=STRING|"json:Customer.Name"
varvalue=STRING|"{Line(1)}"

[Actions\Action12]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""json:Customer.mail"" with value ""{Line(2)}"""
Params=FOLDER

[Actions\Action12\Params]
expand=STRING|"1"
varname=STRING|"json:Customer.mail"
varvalue=STRING|"{Line(2)}"

[Actions\Action13]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//output variables"
Params=FOLDER

[Actions\Action13\Params]
comment=STRING|"output variables"

[Actions\Action14]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message //line"
Params=FOLDER

[Actions\Action14\Params]
message=STRING|"line = {Line}"
type=STRING|"3"

[Actions\Action15]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message //full"
Params=FOLDER

[Actions\Action15\Params]
message=STRING|"Customer = {customer}"
type=STRING|"3"

[Actions\Action16]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message //number"
Params=FOLDER

[Actions\Action16\Params]
message=STRING|"{json:Customer.Number}"
type=STRING|"3"

[Actions\Action17]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message //Name"
Params=FOLDER

[Actions\Action17\Params]
message=STRING|"{json:Customer.Name}"
type=STRING|"3"

[Actions\Action18]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message //mail"
Params=FOLDER

[Actions\Action18\Params]
message=STRING|"{json:Customer.mail}"
type=STRING|"3"

[Actions\Action19]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""first"" with value ""true"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varname=STRING|"first"
varvalue=STRING|"true"

[Actions\Action3]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action3\Params]
message=STRING|"****************"
type=STRING|"3"

[Actions\Action4]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action4\Params]
destvar=STRING|"LINE"
line0=STRING|"{list}"
linecount=STRING|"1"
sourcetext=STRING|"1"

[Actions\Action5]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then //skip 1-st line"
Params=FOLDER

[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{first}"

[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""first"" with value ""false"""
Params=FOLDER

[Actions\Action6\Params]
expand=STRING|"0"
varname=STRING|"first"
varvalue=STRING|"false"

[Actions\Action7]
ActionID=STRING|"A_LOOP_CONTINUE"
Enabled=INTEGER|-1
Name=STRING|"Continue"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action9]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//set variables"
Params=FOLDER

[Actions\Action9\Params]
comment=STRING|"set variables"

Oleg Yershov
Rukbunker
Posts: 192
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: Multiple variables at once

Post by Rukbunker »

Many thanks for cooperating!

However, I see the variables in your script are separated by a space and not a comma or semicolon, or do I miss something?
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Multiple variables at once

Post by Oleg »

...I see the variables in your script are separated by a space and not a comma or semicolon,...
Where? Maybe I don't understand you...
Explain in more details, please
Oleg Yershov
Rukbunker
Posts: 192
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: Multiple variables at once

Post by Rukbunker »

It spits out the variables divided by a space, not a "," or a ";"
Capture.PNG
Capture.PNG (6.01 KiB) Viewed 3872 times
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Multiple variables at once

Post by Oleg »

You gave me CSV text wit COMMA separated lines
The CSV looks like:

Code: Select all

Customernumber,CustomerName,Mail
000001,Robotask,info@dummymail.hay
000052,YankyDoodle,dontwrite@mail.co.uk.br.tr


Also pay attention that strings with spaces or commas "," must be quoted in standard comma-separated string. Like this:

Code: Select all

123456,"Customer with spaces",robotask@robotask.com
Look at new example below. I added Split text action to convert line to standard comma-separated line

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1163085779
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1416"
Hide=INTEGER|0
ID=INTEGER|-369271517
LogOnAsUser=INTEGER|1
Name=STRING|"Set variables from list"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|2
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=FOLDER
Action16=FOLDER
Action17=FOLDER
Action18=FOLDER
Action19=FOLDER
Action2=FOLDER
Action20=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""list"" (source text)"
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"list"
varvalue=STRING|"Customernumber,CustomerName,Mail{EOL}000001,Robotask,info@dummymail.hay{EOL}000052,YankyDoodle,dontwrite@mail.co.uk.br.tr{EOL}000125;Customer with spaces in it's name and semicolon as divider;robotask@robotask.com"

[Actions\Action10]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//set variables"
Params=FOLDER

[Actions\Action10\Params]
comment=STRING|"set variables"

[Actions\Action11]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CustomerNum"" with value ""{Line(0)}"""
Params=FOLDER

[Actions\Action11\Params]
expand=STRING|"1"
varname=STRING|"CustomerNum"
varvalue=STRING|"{Line(0)}"

[Actions\Action12]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CustomerName"" with value ""{Line(1)}"""
Params=FOLDER

[Actions\Action12\Params]
expand=STRING|"1"
varname=STRING|"CustomerName"
varvalue=STRING|"{Line(1)}"

[Actions\Action13]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""mail"" with value ""{Line(2)}"""
Params=FOLDER

[Actions\Action13\Params]
expand=STRING|"1"
varname=STRING|"mail"
varvalue=STRING|"{Line(2)}"

[Actions\Action14]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//output variables"
Params=FOLDER

[Actions\Action14\Params]
comment=STRING|"output variables"

[Actions\Action15]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action15\Params]
message=STRING|"raw line = {RawLine}"
type=STRING|"3"

[Actions\Action16]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action16\Params]
message=STRING|"line = {Line}"
type=STRING|"3"

[Actions\Action17]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action17\Params]
message=STRING|"{CustomerNum}"
type=STRING|"3"

[Actions\Action18]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action18\Params]
message=STRING|"{CustomerName}"
type=STRING|"3"

[Actions\Action19]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action19\Params]
message=STRING|"{Mail}"
type=STRING|"3"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""first"" with value ""true"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varname=STRING|"first"
varvalue=STRING|"true"

[Actions\Action20]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action3]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action3\Params]
message=STRING|"****************"
type=STRING|"3"

[Actions\Action4]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action4\Params]
destvar=STRING|"RAWLINE"
line0=STRING|"{list}"
linecount=STRING|"1"
sourcetext=STRING|"1"

[Actions\Action5]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then //skip 1-st line"
Params=FOLDER

[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{first}"

[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""first"" with value ""false"""
Params=FOLDER

[Actions\Action6\Params]
expand=STRING|"0"
varname=STRING|"first"
varvalue=STRING|"false"

[Actions\Action7]
ActionID=STRING|"A_LOOP_CONTINUE"
Enabled=INTEGER|-1
Name=STRING|"Continue"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action9]
ActionID=STRING|"A_VARIABLES_DELIMITED"
Enabled=INTEGER|-1
Name=STRING|"Split Text //convert to standard comma-separated string"
Params=FOLDER

[Actions\Action9\Params]
colon=STRING|"0"
comma=STRING|"1"
other=STRING|"0"
quote=STRING|"2"
semocolon=STRING|"1"
space=STRING|"0"
spaceasone=STRING|"0"
string=STRING|"{rawline}"
tab=STRING|"0"
variable=STRING|"line"
Oleg Yershov
Rukbunker
Posts: 192
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: Multiple variables at once

Post by Rukbunker »

That was the solution! Many thanks for your time !
Post Reply