Executing javascript (question and ideas)
What javascript execution engine is used? I have having issues with scripts as some functions are not working properly.
Problem 1:
"testString".endsWith("g");
is valid javascript and works with node and browsers. This should return true.
However running this as a script in a workflow results in an error due to it not being a function.
Problem 2:
If I use variables in the script the strings are not escaped.
Variable:
[[testPath]] = "C:\test"
In script:
"[[testPath]]" => "c:est"
Suggestions:
I think it would be very powerful to use node.js as the javascript execution as it is so widely used. Edge.js is a c# library that allows node to easily be executed from .Net. I haven't researched it much but may be an option.
As far as escaping strings you could predefine them all on a javascript object that the script runs in. Instead of using [[varName]] we could just use $ww.varName if we use $ww as the example object that Warewolf populates. This would take care of string escaping problems and even allow complex objects to be manipulated as expected while coding javascript.
Svar
Hi Playsted,
We will look into updating the library in a coming version.
Thanks for the suggestion and thinking on this we will definitely consider it.
Please check the attached (Scritps used to test the Include functionality)
rubySource.rb pythonFile.py endsWith.js startsWith.js
Steps performed:
Using JavaScript
- Test1
- On the Script tool's _Script Syntax _ I typed return "testString".endsWith("g");
- Execution results to an Error
- I clicked include file and included (endsWith.js)
- Execution result returns "True"
You can also attach multiple scripts
Repeat #Test1
now, type: return "testString".startWith("t");
- Execution results to an Error
- I clicked include file and included (startWith.js)
- Execution result returns "True"
--------------------------------------------------------------------------------------------
Same procedure applied when testing the rest of the script types (The other script types I used Numbers to test a GreaterThan function)
Steps performed testing the Escape Charecters Functionality
Using JavaScript
- Test1
Assign [[Value1]] = "C:\test" (including the quotation marks)
On the Script tool's Escape sequence in variables the CheckBox is ticked
On the Script tool's _Script Syntax _ I typed return "the path is : " + [[Value1]]
Execution result is "the path is : C:\test"
- Test2
Untick Escape sequence in variables
Execution result is "the path is : C: est"
- Test3
Change the script content to include more escape sequences
Tick Escape sequence in variables
I typed return "the path is \n " + [[Value1]]
Execution result is "the path is
C:\test"
- Test4
Change the script content to include more escape sequences
UnTick Escape sequence in variables
I typed return "the path is \n " + [[Value1]]
Execution result is "the path is
C: est"
Kundesupport af UserEcho
Hi Playsted,
We will look into updating the library in a coming version.
Thanks for the suggestion and thinking on this we will definitely consider it.