Using Java classes in flow steps with the xMatters Agent

Overview

When executing Flow Designer scripts in the xMatters cloud, certain operations are restricted. For example, scripts can't perform filesystem reads and writes, and they can't add timeouts to the process. However, when flows are triggered on the xMatters Agent, these restrictions are lifted and you can use Java classes to perform operations that the JavaScript language available in the cloud doesn't allow.

This article talks about how to access Java classes in a script to allow operations that cannot be performed with JavaScript.

Preparation

Before you can incorporate Java classes in a flow step, you'll need to download and install the xMatters Agent on a server in your network and configure your flow to execute on the xMatters Agent (not the cloud).

Including Java classes in your script

Here's a simple example of a script that uses the Java PrintWriter class to open a local file, write a string to it, and close the file:

var filePath = "c:/temp/testFile.txt";

console.log("About to write to " + filePath);

var pWriter = new java.io.PrintWriter( filePath );

pWriter.println("This is a test of the Java PrintWriter class.");
var err = pWriter.checkError();
pWriter.close(); 

if ( err ) { 
    console.log( "An unspecified error was encountered while writing to " + filePath ); 
} else { 
    console.log( "Writing to " + filePath + " was successful." ); 
}

Summary

It is generally preferable to use JavaScript rather than Java when writing flow scripts, but in cases where a JavaScript function is unavailable or doesn't exist, you can use a Java class instead.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.