Page 1 of 1

Stop task passing Task External Name by parameter

Posted: Fri Dec 13, 2019 10:10 pm
by juanlu
Hi Oleg,

Currently, the action "Stop Task" can stop the current running task or a specified task. But the specified task is static, not dynamic.

It would be great if the specified task could take a variable, then it would be dynamic. The variable could be e.g. the task name, external name, id or filename of the task we want to stop.

This would also be a very elegant solution for this: https://robotask.com/forum/viewtopic.php?f=1&t=2157 -> just pass to the child task the task external name from the parent task as an input parameter.

This would make the error-handling so much better, specially in the context of making tasks more modular and reusable.

Kind regards, Juanlu.

Re: Stop task passing Task External Name by parameter

Posted: Fri Dec 13, 2019 10:34 pm
by juanlu
Because this is not possible in the GUI, I tried directly putting a variable in the .tsk file. The task was loaded correctly during start up of RoboTask, and it even runs without throwing any errors, but the result of the action Stop Task is "Task not found". When you open the action in the GUI, it just shows Unknown task.

Really a pity.

It looks in the tsk file that what the action is expecting is task id. This can easily be passed from a parent task using {TaskID} (e.g. Parent_Task_ID={TaskID})

Below are my test tasks.

Task for stopping a parent task:

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|563781529
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Stop_parent_task"
Hide=INTEGER|0
ID=INTEGER|1630309343
LocalVariables=STRING|"Parent_Task_ID="
LogOnAsUser=INTEGER|1
Name=STRING|"Stop parent task"
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_TASKS_STOP"
Enabled=INTEGER|-1
Name=STRING|"Stop Task ""!!! Unknown Task !!!"" and terminate it after 60 sec."
Params=FOLDER

[Actions\Action1\Params]
killtask=STRING|"1"
taskid=STRING|"{Parent_Task_ID}"
timeout=STRING|"60"
And parent task to be stopped:

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|563781529
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Parent_task_to_be_stopped"
Hide=INTEGER|0
ID=INTEGER|1990446210
LogOnAsUser=INTEGER|1
Name=STRING|"Parent task to be stopped"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER

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

[Actions\Action1\Params]
message=STRING|"Starting..."
type=STRING|"3"

[Actions\Action2]
ActionID=STRING|"A_TASKS_START"
Enabled=INTEGER|-1
Name=STRING|"Start Task ""Stop parent task"""
Params=FOLDER

[Actions\Action2\Params]
parameter0000=STRING|"Parent_Task_ID={TaskID}"
parametercount=STRING|"1"
required=STRING|"1"
taskid=STRING|"1630309343"
wait=STRING|"1"

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

[Actions\Action3\Params]
message=STRING|"Still running!"
type=STRING|"3"
I do have the impression that implementing this change shouldn't be too difficult; and the benefit would be quite big.

Kind regards, Juanlu.

Re: Stop task passing Task External Name by parameter

Posted: Tue Dec 17, 2019 11:45 am
by Oleg
You can do this by using VB script
Look at my 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
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task611"
Hide=INTEGER|0
ID=INTEGER|-1725643136
LogOnAsUser=INTEGER|1
Name=STRING|"Stop task by using variable"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""EXTNAME"" with value ""TestTaskForStop"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"EXTNAME"
varvalue=STRING|"TestTaskForStop"

[Actions\Action2]
ActionID=STRING|"A_SCRIPT_VBSCRIPT"
Enabled=INTEGER|-1
Name=STRING|"VB Script"
Params=FOLDER

[Actions\Action2\Params]
expandvars=STRING|"0"
line00000000=STRING|"nm = RoboTaskApp.ExpandText(""{ExtName}"")"
line00000001=STRING|"logmessage(""Stopping the task '"" + nm + ""'"")"
line00000002=STRING|"RoboTaskApp.stoptask(nm)"
linecount=STRING|"3"
savescript=STRING|"0"


Re: Stop task passing Task External Name by parameter

Posted: Tue Dec 17, 2019 4:54 pm
by juanlu
Thanks for the reply. Will try that, looks promising.

Re: Stop task passing Task External Name by parameter

Posted: Tue Dec 17, 2019 5:04 pm
by juanlu
Works perfectly! Thanks a lot!