This example will provide instructions for setting up and using Prescripts and Postscripts. Prescripts and Postscripts run code before or after an action or trigger executes. These scripts eliminate having to create small, lightweight Java Actions for simple tasks such as mapping variables to the flow context. These scripts also simplify your workflow, reducing the number of Runtime Data Maps required to be configured to simply map a variable to the flow context. These scripts can accomplish anything a Java Action can without having to worry about class paths.
This example will highlight the use of Postscripts and Prescripts as well as how much they can simplify a workflow. A null action is used for simplicity and a Postscript is added.
Viewing the Example Files
Your Flux installation includes a working, pre-constructed version of this example. To load the example file:
- Click the "Repository" tab.
- Choose the "Workflows" option.
- Click the "Upload" button.
In the dialog that appears, browse to <Flux Home>/examples/end_users/scripting, and select the .ffc file located there.
When the workflow finishes uploading, select it from the grid and choose the "Edit" button to view the workflow in the Designer.
Navigating to the Designer
The Flux Designer will be used to create and execute the example workflow. To use the Designer, browse to the Operations Console and select the "Designer" tab.
When you visit the Designer, you'll se a blank workspace representing the new workflow. To create the example, we'll start by populating the workflow with a few actions.
When you return to the Designer, you will see a blank workspace representing the new workflow. To create the example, you will need to populate the new workflow with a few actions.
To add an action to the workflow, you'll first need to select the action's category in the panel to the left of the workspace. Once you've selected the appropriate category, the action will appear in the panel – left-click the action and drag it onto the Designer workspace to add it to the workflow.
The following table contains the type, category, and quantity of each trigger and action we'll use in this example.
Editing Action Properties
Now that the workflow is created, we add a postscript to the null action. This script will retrieve the action's name from the flow context and then print it to the console.
To add the script, double-click the null action in the Designer. Select "Show More Properties", then click the icon next to the postscript property. This will open the postscript editor; add the following code here:
Save the postscript once this is complete. This code uses a special method, print, that displays the specified argument in standard output.
Since this is a postscript, the code will run once the action is complete.
Running the Workflow
Click the "Export to Engine" button to start the workflow.
If you view the standard output for your engine, you'll now see the words "Null Action" displayed. As you can see, prescripts and postscripts provide an incredible amount of flexibility for your workflows. These scripts can simplify workflows or allow you to execute simple code without requiring a Java Action.