JS Script variables

Discuss RoboTask here
Post Reply
rgonzalez
Posts: 41
Joined: Fri Nov 26, 2010 10:19 am

JS Script variables

Post by rgonzalez »

How can I set a var in javascript that I can use later in robotask?

Example:

Code: Select all

if("{lenel_pte}" < 0 || "{lenel_central}" < 0)
{
//RoboTaskApp.SetUserVariable("ping_error", "true")
ping_error = "true";
}
How to set ping_error to true or some value and then have robotask to read it? I'm doing this with JS Script since there's no IF with OR or AND

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

Re: JS Script variables

Post by Oleg »

To get variable value use ExpandText method of RoboTaskApp.
for example:
pte = RoboTaskApp().ExpandText('{Lenel_pte}');

To set the value use SetUserVariable method

See 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|1416408852
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task22"
Hide=INTEGER|0
ID=INTEGER|2117372526
LogOnAsUser=INTEGER|1
Name=STRING|"Get and Set variables in JS"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

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

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""LENEL_PTE"" with value ""-1"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"LENEL_PTE"
varvalue=STRING|"-1"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""LENEL_CENTRAL"" with value ""50"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"LENEL_CENTRAL"
varvalue=STRING|"50"

[Actions\Action3]
ActionID=STRING|"A_SCRIPT_JSSCRIPT"
Enabled=INTEGER|-1
Name=STRING|"JS script"
Params=FOLDER

[Actions\Action3\Params]
expandvars=STRING|"0"
line00000000=STRING|"pte = RoboTaskApp().ExpandText('{Lenel_pte}');"
line00000001=STRING|"central = RoboTaskApp().ExpandText('{Lenel_Central}');"
line00000003=STRING|"LogMessage(pte);"
line00000004=STRING|"LogMessage(central);"
line00000006=STRING|"if ((pte<0) || (central<0))"
line00000007=STRING|"  {"
line00000008=STRING|"    RoboTaskApp().SetUserVariable('ping_error','True');"
line00000009=STRING|"  }"
line0000000A=STRING|"  else"
line0000000B=STRING|"  {"
line0000000C=STRING|"    RoboTaskApp().SetUserVariable('ping_error','False');"
line0000000D=STRING|"  }"
linecount=STRING|"17"
savescript=STRING|"0"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Lenel_PTE = {Lenel_PTE}"""
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"Lenel_PTE = {Lenel_PTE}"
msg1=STRING|"Lenel_Central = {Lenel_Central}"
msg2=STRING|"Ping_Error = {Ping_Error}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"
Oleg Yershov
rgonzalez
Posts: 41
Joined: Fri Nov 26, 2010 10:19 am

Re: JS Script variables

Post by rgonzalez »

Thank you! :D
Post Reply