Populate Two Local Variables from text or csv file

Discuss RoboTask here
waldo
Posts: 56
Joined: Fri Sep 24, 2004 3:36 am

Populate Two Local Variables from text or csv file

Post by waldo »

Oleg,
I have a single line task with two local variables: batchnumber and emailaddress.

Is there a procedure for Robotask to "read" a csv file to populate the two variables? If so, Robotask then executes the task on the first pass. Once the first iteration is completed, then Robotask "reads" the next line in the csv file to replace the values in the two variables and executes the same task again. I would like this cycle to continue until Robotask "reads" all the lines in the csv file. Once Robotask reaches the end of the CSV file, the task cycle is halted as all batches for that day have been processed. The number of lines with the two variables in the csv file will vary by business day depending on the number of batches processed by the sales department. The each line of the csv file would contain a batchnumber, emailaddress .

Is this possible? If not, any alternative recommendations using Robotask to get me close to the objective?

Thank you
JimC
Oleg
Site Admin
Posts: 3004
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Populate Two Local Variables from text or csv file

Post by Oleg »

You must make 2 tasks
1-st task reads CSV file in the Text Loop and extracts necessary data from each line. Also it starts 2-nd task and pass parameters to it
2-nd task should process accepted data.

Look at my small example. I tested it on such CSV file:

Code: Select all

123,"John smith",j.smith@blacksmith.com
234,"Mary Wood",mary@mwood.com
345,"John Dou",nothing@nowhere.com 
1-st task reads CSV file

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task177"
Hide=INTEGER|0
ID=INTEGER|1455964738
LogOnAsUser=INTEGER|1
Name=STRING|"CSV task1"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|2
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

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

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

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""FILENAME"" with value ""D:\Temp\test.csv"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varname=STRING|"FILENAME"
varvalue=STRING|"D:\Temp\test.csv"

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

[Actions\Action3\Params]
destvar=STRING|"LINE"
file=STRING|"{filename}"
linecount=STRING|"0"
sourcetext=STRING|"0"

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

[Actions\Action4\Params]
expand=STRING|"1"
varname=STRING|"BATCHNUMBER"
varvalue=STRING|"{line(0)}"

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

[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"EMAILADDRESS"
varvalue=STRING|"{line(2)}"

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

[Actions\Action6\Params]
message=STRING|"num: {batchnumber}; address: {emailaddress} "
type=STRING|"3"

[Actions\Action7]
ActionID=STRING|"A_TASKS_START"
Enabled=INTEGER|-1
Name=STRING|"Start Task ""CSV task2"""
Params=FOLDER

[Actions\Action7\Params]
parameter0000=STRING|"num={batchnumber}"
parameter0001=STRING|"addr={emailaddress}"
parametercount=STRING|"2"
required=STRING|"1"
taskid=STRING|"-192327695"
wait=STRING|"1"

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

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

[Actions\Action9\Params]
message=STRING|"*** end ***"
type=STRING|"3"
2-nd task accepts necessary parameters from 1-st task

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task180"
Hide=INTEGER|0
ID=INTEGER|-192327695
LogOnAsUser=INTEGER|1
Name=STRING|"CSV task2"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER

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

[Actions\Action1\Params]
message=STRING|"num: {num}; address: {addr} "
type=STRING|"3"
Save the text of the tasks to a file and use menu Task->Import to import the tasks into RoboTask.
Oleg Yershov
waldo
Posts: 56
Joined: Fri Sep 24, 2004 3:36 am

Re: Populate Two Local Variables from text or csv file

Post by waldo »

Oleg,
Thank you for the help. I am stuck and it is my own fault. After I get the first line in the csv file and it passes the values for the variables batchnumber and e-mail_address, the task below runs. This task runs now when I populate the variables manually before each run. Where do I place this task line in the "second" task? Thanks for your patience. Jim

Code: Select all

-report="C:\Users\jcff.\Desktop\Crystal_Reports_Master\Crystal_Reports\Time_Card_Reports_for_email\Time_card_report_2020_by_Time_batch_number_ver4A.rpt" -login!="" -suppressempty -refresh -exportformat=PDF -exportfile="time_entry.pdf" -emserver=internalserver -emsender="johndoe@gmail.com" -emrecipient=""{email_address}"" -emsubject="Time Entry Report for your Review & Approval "{BatchNumber}"" -emtext="This is an automated e-mail.   Please review the attached report and indicate changes otherwise if the time entry is accurate, please authorize accounting to finalize the time entry." -emuserid="madeupnamehere" -empassword!="HS57ZNq@qBZVYZ8KYR18GzN2lj8SeeeeM3b" -logfile="${TEMP}\${Report.Name}.log" -appendlog -parameters  "{BatchNumber}"
Oleg
Site Admin
Posts: 3004
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Populate Two Local Variables from text or csv file

Post by Oleg »

What is it?

Code: Select all

-report="C:\Users\jcff.\Desktop\Crystal_Reports_Master\Crystal_Reports\Time_Card_Reports_for_email\Time_card_report_2020_by_Time_batch_number_ver4A.rpt" -login!="" -suppressempty -refresh -exportformat=PDF -exportfile="time_entry.pdf" -emserver=internalserver -emsender="johndoe@gmail.com" -emrecipient=""{email_address}"" -emsubject="Time Entry Report for your Review & Approval "{BatchNumber}"" -emtext="This is an automated e-mail.   Please review the attached report and indicate changes otherwise if the time entry is accurate, please authorize accounting to finalize the time entry." -emuserid="madeupnamehere" -empassword!="HS57ZNq@qBZVYZ8KYR18GzN2lj8SeeeeM3b" -logfile="${TEMP}\${Report.Name}.log" -appendlog -parameters  "{BatchNumber}"
I think that this is some command line, correct?
But I don't see application executable...

Use Run Program/Open Document action to run some command-line utilty
Also use wait option Wait untill the application exits. In this case the action will wait until the utility finish its work.
Oleg Yershov
waldo
Posts: 56
Joined: Fri Sep 24, 2004 3:36 am

Re: Populate Two Local Variables from text or csv file

Post by waldo »

Oleg--Yes, it is a command line. I will double check as maybe it didn't copy correctly from my manually created task. I will also add the Wait command. I will post back. Thank you!!! Jim
waldo
Posts: 56
Joined: Fri Sep 24, 2004 3:36 am

Re: Populate Two Local Variables from text or csv file

Post by waldo »

Oleg, thank you. Do I need to set my local variables as follows: BatchNumber = Num and Email_adress = address or do I merely leave them without a value in Task2 as the values are automatically passed from Task1? Jim
Oleg
Site Admin
Posts: 3004
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Populate Two Local Variables from text or csv file

Post by Oleg »

as you wish

In my example task1 pass to task2 two parameters num and addr
This means that task2 has two initiated variables num and addr which you can use in the task
You can change names of parameters if it's necessary or save values to another variables or compose some expression with these variables.
You can do anything as you wish.
Oleg Yershov
waldo
Posts: 56
Joined: Fri Sep 24, 2004 3:36 am

Re: Populate Two Local Variables from text or csv file

Post by waldo »

Oleg,
Sorry, I did not see your response before posting this post. I have done more testing. If I run both tasks (modified to my directory path), but when I declare both variables equal to a batch number and e-mail address, then I do generate three e-mails--all identical using the "fixed" batch number and e-mail address I set the variables equal to. Expected behavior since I set the variables equal to the batch number and email address. But if I leave the variables undeclared, no e-mails are generated. Also when I set BatchNumber = Num and email_address = address--I would think this would work. But it does not So it appears that the variables read in the CSV file are not making it to the actual variables. Jim
Oleg
Site Admin
Posts: 3004
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Populate Two Local Variables from text or csv file

Post by Oleg »

you do not need to make variable declarations.
declarations will override parameters.

Look at my examples. These tasks have no declarations at all.
Oleg Yershov
waldo
Posts: 56
Joined: Fri Sep 24, 2004 3:36 am

Re: Populate Two Local Variables from text or csv file

Post by waldo »

Oleg--ok. I will re-name my variables in the command line to match what was used in your file---num and addr. I will report back. Again, thank you for all of your help. Jim
Post Reply