Robot execution on local machine, Control Tower, and RPA Node
One of common issues with Groovy RPA scripts is: a script is successfully executed on a local machine (WF Studio), but fails when it is executed in Control Tower as a Bot Task.
To avoid this issue, you need to know the following rules:
- If you want the script to be executed on the RPA Node machine
(RPA Windows server):
- Put the script inside this
method:
desktopDriver.executeScript(script, "GROOVY") - The code above should be inside the
<robot>plugin.
- Put the script inside this
method:
- If you want the script to be executed on your local machine:
- Write your code inside a
<script>section. - Run Bot config from WorkFusion Studio.
- Write your code inside a
- If you want the script to be executed on the Control Tower
server (typically it is a Linux machine):
- Write your code inside a
<script>section. - Export your config to Control Tower as a Bot Task and place it in a business process.
- Run your business process.
- Write your code inside a
Therefore, you need to pay attention to the file paths you are using in
your scripts: C:/tmp/test/1.txt - will not exist on a Linux
machine (Control Tower).**
If you have this file on your local machine, make sure it is accessible under the same path on the target RPA Node.
See the following examples for better understanding (comment blocks show where the script will be executed):
Example 1
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">
<var-def name="copyFile">
java.io.File sourceFile = new java.io.File("C:\\tmp\\test\\1.txt");
java.io.File destFile = new java.io.File("C:\\tmp\\test\\345.txt");
java.io.InputStream is = null;
try {
is = new java.io.FileInputStream(sourceFile);
java.nio.file.Files.copy(is, destFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
} catch(Exception e) {
e.printStackTrace();
} finally {
if (is != null) is.close();
}
</var-def>
<!-- executing on WF or Studio machine (JVM) -->
<script></script>
<robotics-flow>
<robot driver="desktop" name="desktopWrapper">
<!-- executing on node machine (JVM) -->
<script></script>
<!-- executing on WF or Studio machine (JVM) -->
<script></script>
</robot>
</robotics-flow>
<export include-original-data="true"></export>
</config>
Example 2
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">
<!-- executing on WF or Studio machine (JVM) -->
<script><![CDATA[
java.io.File sourceFile = new java.io.File("C:\\tmp\\test\\1.txt");
java.io.File destFile = new java.io.File("C:\\tmp\\test\\345.txt");
java.io.InputStream is = null;
try {
is = new java.io.FileInputStream(sourceFile);
java.nio.file.Files.copy(is, destFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
} catch(Exception e) {
e.printStackTrace();
} finally {
if (is != null) is.close();
}
]]></script>
<robotics-flow>
<robot driver="desktop" name="desktopWrapper">
<!-- executing on node machine (JVM) -->
<script><![CDATA[
desktopDriver = desktopWrapper.getWrappedObject();
String script = "java.io.File sourceFile = new java.io.File(\"C:\\\\tmp\\\\test\\\\1.txt\");\n"+
"java.io.File destFile = new java.io.File(\"C:\\\\tmp\\\\test\\\\345.txt\");\n"+
"java.io.InputStream is = null;\n"+
"try {\n"+
"is = new java.io.FileInputStream(sourceFile);\n"+
"java.nio.file.Files.copy(is, destFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);\n"+
"} catch(Exception e) {\n"+
"e.printStackTrace();\n"+
"} finally {\n"+
"if (is != null) is.close();\n"+
"}\n";
desktopDriver.executeScript(script, "GROOVY");
]]></script>
</robot>
</robotics-flow>
<export include-original-data="true"></export>
</config>