User Tools

Site Tools


SET PROTOTYPE

Guide Section: Processing Events and Performing Actions
EASAP Tree: EVENT PROCESSING > ACTION

SET PROTOTYPE is an advanced feature used to manipulate LISTs and SCALARs and trigger ACTIONs using the Java-like scripting language Groovy.

Either File: or Text: must contain the Groovy source script.

There must be at least one use of each object listed in:

  • Parameters:
  • Outputs:
  • Action Parameters:

Groovy API Documentation is a useful reference.

SET PROTOTYPE
Essential Parameters:
Parameters:Select input LISTs and SCALARs that will be available by name in the script block
Outputs:Enter names for any new LISTs that will contain output data from a Groovy script
Optional Parameters:
Text: Enter Groovy script text to run
File: Select filename containing the Groovy script text
Action Parameters: Enter names of any ACTION GROUPs which may be ' .run(); ' by the script, example below
Do If:Enter a logical expression which, if true will allow script to be executed

Parameters:

A SCALAR input will be available as a 'Groovy String'.

A LIST input will be available as a 'Groovy Vector'.


Outputs:

New objects in Outputs: will always be explicit LISTs regardless of the context in the Groovy script.

If a Groovy variable has a single value instead of a list of values, an Author will find the single value result as the first value of the explicit LIST.


Three examples

  1. A simple Groovy script
  2. Use of Action Parameters:
  3. 'Pad' the ends of LISTs from Excel prior to writing to a database

1. Simple Groovy script

Below is a simple Groovy script in an EASAP to allow the user to enter a person's name and the script creates a greeting which is displayed in a LABEL.

This example creates an EASAP with the interface below:

  • An INPUTBOX for entering a person's name
  • A BUTTON with a child SET PROTOTYPE
  • A LABEL to display the output DOR, groovyDOR in this case



First set up an EASAP with the objects below:



  • For menu-action1 set Menu Action: Refresh
    This insures that values are refreshed following the script execution.
  • For set_prototype1 set parameters below:

The EASAP executes as follows:

  1. User enters a name
  2. button1 triggers set_prototype1
    Groovy concatenates ' hello ' with inputbox1
    Result is returned as groovyDOR
  3. menu_action1 refreshes all DORs
    groovyDOR is displayed in a LABEL

2. Groovy example using Action Parameters:

The Tree below outlines an EASAP that:

  1. Opens a browser (action_group1) when a TABBED PANE is selected
  2. A BUTTON triggers a SET PROTOTYPE running the script in Text:
    inputbox1 is assigned to output
    action_group1.run() is called, here we run an OPEN BROWSER with URL: http://www.google.com

This scripts requires Parameters:, Outputs: and Action Parameters: to be declared as they are in the screenshot below.


3. Pad LIST's from Excel prior to writing to a database

Reading columns from a single Excel table creates LIST's that vary in length from each other if any of the last element(s) in the column are blank. However DATABASE→WRITE requires LIST's be of equal length. To remedy this in Groovy we create a LIST of blank elements for each column that we will CONCATENATE with the Excel-derived LIST to make all LIST's the same length.

For a SET PROTOTYPE set:

  • Parameters: list1_length, list2_length,list3_length
  • Outputs: col1pad,col2pad,col3pad
  • File: script.txt

This script below creates three lists of blank elements that will be concatenated to each existing LIST to make them all maxLength elements long.

ArrayList<String> col1padding = new ArrayList<>();
ArrayList<String> col2padding = new ArrayList<>();
ArrayList<String> col3padding = new ArrayList<>();
 
int maxLength = 0;
if(maxLength < Integer.valueOf(list1_length)){ maxLength = Integer.valueOf(list1_length); }
if(maxLength < Integer.valueOf(list2_length)){ maxLength = Integer.valueOf(list2_length); }
if(maxLength < Integer.valueOf(list3_length)){ maxLength = Integer.valueOf(list3_length); }
for (int i =0;i<maxLength - Integer.valueOf(list1_length);i++){ col1padding.add(""); }
for (int i =0;i<maxLength - Integer.valueOf(list2_length);i++){ col2padding.add(""); }	
for (int i =0;i<maxLength - Integer.valueOf(list3_length);i++){ col3padding.add(""); }
col1pad=col1padding;
col2pad=col2padding;
col3pad=col3padding;