JavaScript - assign result of fn to variable robotakst

Discuss RoboTask here
Post Reply
felipe
Posts: 24
Joined: Thu Nov 30, 2023 6:18 pm

JavaScript - assign result of fn to variable robotakst

Post by felipe »

function fn(a, b) {
return a + " " + b;

var result = fn("hello", "world");

RoboTaskApp.AddUserVariable(RoboTaskApp.ExpandText(VariableNameResult, result);


could help format the synthase
tks
Oleg
Site Admin
Posts: 3201
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: JavaScript - assign result of fn to variable robotakst

Post by Oleg »

Look at my example below

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
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1465"
Hide=INTEGER|0
ID=INTEGER|2102349058
LogOnAsUser=INTEGER|1
Name=STRING|"JS Script..."
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER

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

[Actions\Action1\Params]
expandvars=STRING|"0"
line00000000=STRING|"function myfn(a, b)"
line00000001=STRING|"  {"
line00000002=STRING|"  return a + "" "" + b;"
line00000003=STRING|"  }"
line00000005=STRING|"VariableNameResult = ""ResVar"";"
line00000006=STRING|"result = myfn(""hello"", ""world"");"
line00000008=STRING|"//logmessage(result);"
line00000009=STRING|"RoboTaskApp().SetUserVariable(VariableNameResult, result);"
linecount=STRING|"11"
savescript=STRING|"0"

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

[Actions\Action2\Params]
message=STRING|"{ResVar}"
type=STRING|"3"

The script is

Code: Select all

function myfn(a, b)
  {
  return a + " " + b;
  }

VariableNameResult = "ResVar";
result = myfn("hello", "world");

RoboTaskApp().SetUserVariable(VariableNameResult, result);
Oleg Yershov
Post Reply