Execute Groovy script
The feature allows executing GroovyScript on a Bot machine (Windows RPA Server), not in Control Tower. For more details, see the JavaDoc link.
You can optionally pass a timeout and parameters for your GroovyScript. The possible variants of the executeGroovyScript() method are as follows:
executeGroovyScript(script)executeGroovyScript(script, timeout)executeGroovyScript(script, scriptParams)executeGroovyScript(script, timeout, scriptParams)
You can create the scriptParams object using the following syntax:
import com.workfusion.rpa.helpers.ScriptParams
// initializing the object
def scriptParams = new ScriptParams(['fileSuffix':'.txt', 'fileData':fileData])
// adding one property
scriptParams.add('filePrefix','temp-')
// adding multiple properties
scriptParams.addAll(['key1':'val1', 'key2':'val2'])
Usage example: local files creation on Bot machine:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">
<robotics-flow>
<robot driver="universal">
<script><![CDATA[
import com.workfusion.rpa.helpers.ScriptParams
byte[] fileData = 'File content data'.getBytes(java.nio.charset.StandardCharsets.UTF_8);
def scriptParams = new ScriptParams(['fileSuffix':'.txt', 'fileData':fileData])
scriptParams.add('filePrefix','temp-')
String nodePathToFile = executeGroovyScript("" +
"import com.google.common.io.Files; \n" +
"File tmp = File.createTempFile(filePrefix, fileSuffix); \n" +
"Files.write(fileData, tmp); \n" +
"return tmp.getAbsolutePath();",
scriptParams
);
log.warn('Node path to file :' + nodePathToFile);
]]></script>
</robot>
</robotics-flow>
<export include-original-data="true"/>
</config>
AutoIt scripts
caution
NOT RECOMMENDED
You can also create AutoIt scripts using the following methods:
executeAutoitScript(script)executeAutoitScript(script, timeout)executeAutoitScript(script, timeout, array)
executeGroovyScript(String code, Map arguments) allows to execute Groovy Script with variables passed as parameters. For more details, refer to the documentation.
executeGroovyScript(String code, Map<Object,Object> arguments)
The mechanism allows to avoid limitation of String size in Java and threat of injection.
Each RPA script instruction, for example, executeGroovyScript, has a predefined timeout of 15 minutes. If your script executes more than this time period, a SocketTimeoutException is thrown.
All variables are transferred in method parameters as a Map (name : value).
Usage sample:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">
<robotics-flow>
<robot driver="desktop">
<script><![CDATA[
byte[] fileData = 'File content data'.getBytes(java.nio.charset.StandardCharsets.UTF_8);
String nodePathToFile = executeGroovyScript("" +
"import com.google.common.io.Files; \n" +
"File tmp = File.createTempFile(\"${filePrefix}\", \"${fileSuffix}\"); \n" +
"Files.write(fileData, tmp); \n" +
"return tmp.getAbsolutePath();",
['filePrefix':'temp-', 'fileSuffix':'.txt', 'fileData':fileData]
);
log.warn('Node path to file :' + nodePathToFile);
]]></script>
</robot>
</robotics-flow>
<export include-original-data="true"/>
</config>