Metastorm BPM : Handling Responses


This may be obvious to more experienced Metastorm 7 developers, but to newbies, it is not always clear how to call a script, web service or stored procedure from Metastorm and handle the response accordingly.  When designing your business objects & services tier of your BPM application, you need to have the process logic (the Metastorm map) call your business logic and when execution is complete, have Metastorm do something with the response. This could mean consuming the response data in the process itself or could simply be a boolean response telling Metastorm that the business logic has successfully run with no errors.

Script Calls

Metastorm 7.x has a built in JScript.NET script editor that is frankly lacking in features.  It does validate your code if you click the ‘validation tick’ button, but that’s where the ‘code support’ ends.  When writing a server side script, normal practice is to receive a set of arguments from the process, wrap your code in try/catch blocks and then optionally return a success or fail value back to the process, this is done using the %ScriptEval() function. This method will execute the specified server side script and return a response back to Metastorm based on the ‘return’ keyword in your code. e.g. Here’s a quick script that consumes a dll in the dotnetbin on the Metastorm server (click here for a slightly larger image):

This script takes several arguments from the process and returns two possible responses.  The first tells Metastorm that the script has run successfully by returning a path to a document and the second returns the response if an exception is caught in the code, which is very useful whilst troubleshooting complex scripts.  To call the above script, I code the following (bigger image here):

As we call Web Services via server side scripts, you can also return responses back to Metastorm with this same method.

Stored Procedure Calls

Some developers run their business logic using stored procedures.  As before, the process needs to know how the stored procedure has gotten on with its execution and so we need to call the stored procedure and accept a response back so we can process decisions on how to proceed.  There is a built in function called %ExecProc() but the best way to receive a value back from a stored procedure is to create an out variable in the stored procedure and SELECT it using a %SelectSQL() call.  For example (bigger):

The output variable is returned to the %Result variable in Metastorm and using this you can make your subsequent process decisions.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s