Saving Exception Messages Using the Execute Script Service

If you are handy with the Java language, you probably already know how to use the Execute Script service to interact with the process data model. The LiveCycle Workbench ES Help describes all the methods that are inherently available to the Execute Script service for getting and setting process variable values. (See patExecContext reference). However, you can also code against any of the Java libraries that are available to the Java virtual machine that runs the LiveCycle ES server.

The following simple example creates a new file named temp.txt on the C:\ drive of the LiveCycle ES server:import;import;//create a File objectFile newDir = new File(“c:\\temp.txt”);boolean created;try {//write the file to the file systemcreated = newDir.createNewFile();//save the resultpatExecContext.setProcessDataBooleanValue(“/proces_data/@fileCreated”, created);} catch (IOException e) {//save the error messagepatExecContext.setProcessDataStringValue(“/pricess_data/@results”,”Error in Create File process: “ + e.getMessage());}This is a trivial use case, especially considering that you can use the File Utilities service to create a file. Notice, though, that if an exception is thrown the error message is saved in a process variable. Even though service operations throw exception events, the events do not provide information about the exception. Exception events are great tools for reacting to unexpected behaviors such as execution errors, but they aren’t very helpful for investigating the cause of the behavior. The Execute Script service enables you to incorporate the exception details into the process.I created a process that included the Execute Script service using the Java code from the above example. To throw an exception, I changed the file name to FF:\\temp.txt (no FF drive exists on the file system of the LiveCycle ES server). When I invoked the process, the exception message, “The system cannot find the path specified,” is saved in the results variable. The process also uses routing conditions to evaluate the results variable and email the exception message to the process owner.process.gif

VN:F [1.9.22_1171]
Was this helpful? Please rate the content.
Rating: 0.0/10 (0 votes cast)

Comments are closed.