Page 1 of 1
Working with workdays
Posted: Mon Feb 22, 2016 5:24 pm
by Rukbunker
Dear Robotaskers,
My "normal" Robotask skills are good, but programming is too far away for me. What is the situation?
The local financial department wants to have a process of creating a financial report automated. In fact no problem but there is a special condition.
Normally, the report uses a variable "end date" which is always 31-[mm]-[yyyy], even when it's February. The program which gets this input from Robotask accepts this. Thankgod!
BUT!
If the moment of execution of the task is on the 4th WORKING day of the current month or earlier, then the "end date" should be 31-[mm]-[yyyy]
of the PREVIOUS month, so something like 31-[mm-1]-[yyyy]. So, if the report is being executed on 04-02-2016 (DD-MM-YYYY) which is a Thursday, the end date must be 31-01-2016.
If the moment of execution of the task is on the 5th WORKING day of the current month or later, then the "end date" should be 31-[mm]-[yyyy]
of the CURRENT month.
So, if the report is being executed on 05-02-2016 (DD-MM-YYYY) which is a Friday, the end date must be 31-02-2016.
Somewhere I have to define the workdays (Monday till Friday) and I have to combine it with a IF, THEN, ELSE statement. The question is: how can I solve this?
Thanks in advance!
Re: Working with workdays
Posted: Tue Feb 23, 2016 12:49 pm
by Oleg
Let I formulate the job:
You have some date in format DD-MM-YYYY
You need to calculate the LASTDATE
if DD from 1 to 4 then the LASTDATE equals to 31-(MM-1)-YYYY
if DD from 5 to 31 then the LASTDATE equals to 31-MM-YYYY
Did I understood you correctly? If so, I can write small example to you.
Re: Working with workdays
Posted: Tue Feb 23, 2016 1:48 pm
by Rukbunker
Thanks for your quick reply, Oleg.
You're almost there. The question is not DD from 1 to 4 (just the number of days), but it's about
working days, Mon, Tue, Wed, Thu and Fri.
If #workingday in a month <= 4, then the LASTDATE equals to 31-(MM-1)-YYYY
If #workingday in a month => 5, then the LASTDATE equals to 31-(MM)-YYYY
For example we take June 2016:
June 1, 2 and 3 are working days. June 4 and 5 not. June 6 is again a working day, but it's the 4TH workingday of that month. Then is still should be 31-(MM-1)-YYYY. From June 7th and further (= 5th working day) it should be 31-(MM)-YYYY.
Let's call this a challenge

Re: Working with workdays
Posted: Tue Feb 23, 2016 3:57 pm
by Oleg
What about Saturday and Sunday? Raise an error?
Re: Working with workdays
Posted: Tue Feb 23, 2016 4:36 pm
by Rukbunker
The task itself runs only on workdays (Mo .. Fr). In fact he should give no error
Maybe we have to think of an array with only the 5 working days in it, no idea. Just guessing.
Re: Working with workdays
Posted: Wed Feb 24, 2016 9:11 am
by Oleg
See the example below
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
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
ExternalName=STRING|"Task53"
Hide=INTEGER|0
ID=INTEGER|239237499
LogOnAsUser=INTEGER|1
Name=STRING|"Last Date"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
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
Action21=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER
[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|0
Name=STRING|"Set variable ""CURRENTDT"" with value ""{DateTimeToFormat({Date},dd-mm-yyyy)}"""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"1"
varname=STRING|"CURRENTDT"
varvalue=STRING|"{DateTimeToFormat({Date},dd-mm-yyyy)}"
[Actions\Action10]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then (month = 1)"
Params=FOLDER
[Actions\Action10\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"1"
value1=STRING|"{mm}"
value2=STRING|"1"
[Actions\Action11]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""yy"""
Params=FOLDER
[Actions\Action11\Params]
incement=STRING|"-1"
vaiable=STRING|"yy"
[Actions\Action12]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LASTDATE"" with value ""31-12-{yy}"""
Params=FOLDER
[Actions\Action12\Params]
expand=STRING|"1"
varname=STRING|"LASTDATE"
varvalue=STRING|"31-12-{yy}"
[Actions\Action13]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"
[Actions\Action14]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""mm"""
Params=FOLDER
[Actions\Action14\Params]
incement=STRING|"-1"
vaiable=STRING|"mm"
[Actions\Action15]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action15\Params]
case=STRING|"0"
operator=STRING|"5"
type=STRING|"1"
value1=STRING|"{mm}"
value2=STRING|"10"
[Actions\Action16]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""MM"" with value ""0{mm}"""
Params=FOLDER
[Actions\Action16\Params]
expand=STRING|"1"
varname=STRING|"MM"
varvalue=STRING|"0{mm}"
[Actions\Action17]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action18]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LASTDATE"" with value ""31-{mm}-{yy}"""
Params=FOLDER
[Actions\Action18\Params]
expand=STRING|"1"
varname=STRING|"LASTDATE"
varvalue=STRING|"31-{mm}-{yy}"
[Actions\Action19]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CURRENTDT"" with value ""03-02-2016"""
Params=FOLDER
[Actions\Action2\Params]
expand=STRING|"1"
varname=STRING|"CURRENTDT"
varvalue=STRING|"03-02-2016"
[Actions\Action20]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action21]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Current date = {currentDT}"""
Params=FOLDER
[Actions\Action21\Params]
icon=STRING|"1"
msg0=STRING|"Current date = {currentDT}"
msg2=STRING|"Last date = {LastDate}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LASTDATE"" with value ""UNKNOWN"""
Params=FOLDER
[Actions\Action3\Params]
expand=STRING|"0"
varname=STRING|"LASTDATE"
varvalue=STRING|"UNKNOWN"
[Actions\Action4]
ActionID=STRING|"A_STR_EXTRACT"
Enabled=INTEGER|-1
Name=STRING|"STR Extract (day)"
Params=FOLDER
[Actions\Action4\Params]
amount=STRING|"2"
from=STRING|"1"
source=STRING|"{CurrentDT}"
variable=STRING|"dd"
[Actions\Action5]
ActionID=STRING|"A_STR_EXTRACT"
Enabled=INTEGER|-1
Name=STRING|"STR Extract (month)"
Params=FOLDER
[Actions\Action5\Params]
amount=STRING|"2"
from=STRING|"4"
source=STRING|"{CurrentDT}"
variable=STRING|"mm"
[Actions\Action6]
ActionID=STRING|"A_STR_EXTRACT"
Enabled=INTEGER|-1
Name=STRING|"STR Extract (year)"
Params=FOLDER
[Actions\Action6\Params]
amount=STRING|"4"
from=STRING|"7"
source=STRING|"{CurrentDT}"
variable=STRING|"yy"
[Actions\Action7]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then (day >= 5)"
Params=FOLDER
[Actions\Action7\Params]
case=STRING|"0"
operator=STRING|"2"
type=STRING|"1"
value1=STRING|"{dd}"
value2=STRING|"5"
[Actions\Action8]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LASTDATE"" with value ""31-{mm}-{yy}"""
Params=FOLDER
[Actions\Action8\Params]
expand=STRING|"1"
varname=STRING|"LASTDATE"
varvalue=STRING|"31-{mm}-{yy}"
[Actions\Action9]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"
Re: Working with workdays
Posted: Wed Feb 24, 2016 4:06 pm
by Rukbunker
Many thanks! I will give it a try and let you know!
Re: Working with workdays
Posted: Wed Feb 24, 2016 4:17 pm
by Rukbunker
I have tested it and the script works perfectly. But....he "counts" the total number of days, including weekends. He should only count
workingdays.....
I've tried to convince the Fin. dept. to change it, but it was no option

Re: Working with workdays
Posted: Wed Feb 24, 2016 5:42 pm
by Oleg
Look at the task version 2
I added the step #7 (
JS Evaluate)
Unfortunately the usage of Javascript is more simple than calculation of this in simple actions of RoboTask.
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
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
ExternalName=STRING|"Task53"
Hide=INTEGER|0
ID=INTEGER|239237499
LogOnAsUser=INTEGER|1
Name=STRING|"Last Date (version 2)"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
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
Action21=FOLDER
Action22=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER
[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|0
Name=STRING|"Set variable ""CURRENTDT"" with value ""{DateTimeToFormat({Date},dd-mm-yyyy)}"""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"1"
varname=STRING|"CURRENTDT"
varvalue=STRING|"{DateTimeToFormat({Date},dd-mm-yyyy)}"
[Actions\Action10]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"
[Actions\Action11]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then (month = 1)"
Params=FOLDER
[Actions\Action11\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"1"
value1=STRING|"{mm}"
value2=STRING|"1"
[Actions\Action12]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""yy"""
Params=FOLDER
[Actions\Action12\Params]
incement=STRING|"-1"
vaiable=STRING|"yy"
[Actions\Action13]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LASTDATE"" with value ""31-12-{yy}"""
Params=FOLDER
[Actions\Action13\Params]
expand=STRING|"1"
varname=STRING|"LASTDATE"
varvalue=STRING|"31-12-{yy}"
[Actions\Action14]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"
[Actions\Action15]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""mm"""
Params=FOLDER
[Actions\Action15\Params]
incement=STRING|"-1"
vaiable=STRING|"mm"
[Actions\Action16]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action16\Params]
case=STRING|"0"
operator=STRING|"5"
type=STRING|"1"
value1=STRING|"{mm}"
value2=STRING|"10"
[Actions\Action17]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""MM"" with value ""0{mm}"""
Params=FOLDER
[Actions\Action17\Params]
expand=STRING|"1"
varname=STRING|"MM"
varvalue=STRING|"0{mm}"
[Actions\Action18]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action19]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LASTDATE"" with value ""31-{mm}-{yy}"""
Params=FOLDER
[Actions\Action19\Params]
expand=STRING|"1"
varname=STRING|"LASTDATE"
varvalue=STRING|"31-{mm}-{yy}"
[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CURRENTDT"" with value ""06-01-2016"""
Params=FOLDER
[Actions\Action2\Params]
expand=STRING|"1"
varname=STRING|"CURRENTDT"
varvalue=STRING|"06-01-2016"
[Actions\Action20]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action21]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action22]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Current date = {currentDT}"""
Params=FOLDER
[Actions\Action22\Params]
icon=STRING|"1"
msg0=STRING|"Current date = {currentDT}"
msg2=STRING|"Last date = {LastDate}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LASTDATE"" with value ""UNKNOWN"""
Params=FOLDER
[Actions\Action3\Params]
expand=STRING|"0"
varname=STRING|"LASTDATE"
varvalue=STRING|"UNKNOWN"
[Actions\Action4]
ActionID=STRING|"A_STR_EXTRACT"
Enabled=INTEGER|-1
Name=STRING|"STR Extract (day)"
Params=FOLDER
[Actions\Action4\Params]
amount=STRING|"2"
from=STRING|"1"
source=STRING|"{CurrentDT}"
variable=STRING|"dd"
[Actions\Action5]
ActionID=STRING|"A_STR_EXTRACT"
Enabled=INTEGER|-1
Name=STRING|"STR Extract (month)"
Params=FOLDER
[Actions\Action5\Params]
amount=STRING|"2"
from=STRING|"4"
source=STRING|"{CurrentDT}"
variable=STRING|"mm"
[Actions\Action6]
ActionID=STRING|"A_STR_EXTRACT"
Enabled=INTEGER|-1
Name=STRING|"STR Extract (year)"
Params=FOLDER
[Actions\Action6\Params]
amount=STRING|"4"
from=STRING|"7"
source=STRING|"{CurrentDT}"
variable=STRING|"yy"
[Actions\Action7]
ActionID=STRING|"A_SCRIPT_JSEVALUATE"
Enabled=INTEGER|-1
Name=STRING|"JS Evaluate (calculates NUM of working day)"
Params=FOLDER
[Actions\Action7\Params]
expression=STRING|"getworkday({dd},{mm},{yy})"
line00000000=STRING|"function getworkday(d,m,y)"
line00000001=STRING|"{"
line00000002=STRING|" workday = 0;"
line00000003=STRING|" m--; // month begins from 0 in Javascript"
line00000004=STRING|" dt = new Date(y, m, d);"
line00000006=STRING|" weekday = dt.getDay();"
line00000007=STRING|" // 0 Sunday"
line00000008=STRING|" // 1 Monday"
line00000009=STRING|" // 2 Tuesday"
line0000000A=STRING|" // 3 Wednesday"
line0000000B=STRING|" // 4 Thursday"
line0000000C=STRING|" // 5 Friday"
line0000000D=STRING|" // 6 Saturday"
line0000000E=STRING|" for (i=d; i>0; i--)"
line0000000F=STRING|" {"
line00000010=STRING|" if ((weekday != 6) && (weekday != 0))"
line00000011=STRING|" {"
line00000012=STRING|" workday++;"
line00000013=STRING|" }"
line00000014=STRING|" weekday--;"
line00000015=STRING|" if (weekday <0)"
line00000016=STRING|" {weekday = 6;"
line00000017=STRING|" }"
line00000018=STRING|" }"
line00000019=STRING|" return workday;"
line0000001A=STRING|"}"
line0000001C=STRING|"//LogMessage(getworkday(7,1,2016));"
linecount=STRING|"29"
loadfromfile=STRING|"1"
variable=STRING|"workday"
[Actions\Action8]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then (day >= 5)"
Params=FOLDER
[Actions\Action8\Params]
case=STRING|"0"
operator=STRING|"2"
type=STRING|"1"
value1=STRING|"{workday}"
value2=STRING|"5"
[Actions\Action9]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LASTDATE"" with value ""31-{mm}-{yy}"""
Params=FOLDER
[Actions\Action9\Params]
expand=STRING|"1"
varname=STRING|"LASTDATE"
varvalue=STRING|"31-{mm}-{yy}"
Re: Working with workdays
Posted: Wed Feb 24, 2016 8:36 pm
by Rukbunker