This section provides examples of common operations that you can perform using ECMAScript.
To create a function in the ECMA expression builder, create the function inline:
function abc() { var v1 = "" ; for ( i = 0; i < 9 ; i++) v1 += "$"; return v1; } ; abc();
This section presents scripting examples that show the use of the flowdata object.
Suppose you entered information about an approval status into the flowdata by creating an XML element named start_reason with a child element named approval_reason and an attribute named ApprovalStatus. Use the following expression in a pre-activity map to retrieve the value of the ApprovalStatus attribute:
flowdata.get('start_reason/approval_reason/@ApprovalStatus')
You can enter this expression by expanding the
nodes in the ECMAScript Variables pane of the ECMA expression builder and double-clicking the ApprovalStatus attribute.You can add information to the flowdata so that it can be used by a downstream activity. Use the following expression in a post-activity map:
flowdata.start_reason/approval_reason/@ApprovalStatus
This section presents several examples of scripting with form controls.
Suppose you have a form field named ApprovalStatus. To get the value of this field, use the following expression in a pre-activity map:
process.get('ApprovalStatus')
You can enter this expression by opening the Process node in the ECMAScript Variables pane of the ECMA expression builder and double-clicking ApprovalStatus.
To get an individual value from a multivalued control (for example, a check box named colors), you first need to get the control into the flowdata. In the post-activity mapping for an upstream activity, use the following:
flowdata.colors
To get a value from colors (for example, the first value), use the following expression on a downstream activity:
flowdata.getObject(‘colors[1]’)
To populate list controls (for example, PickList or MVEditor) or the MVCheckbox control by using script, use an expression like this in the pre-activity mapping:
function list() {var l=new java.util.Vector();l.add(‘Blue’);l.add(‘Red’); l.add(‘Green’); return l;} list();
To compare DNs to find out if they are equal, use an expression like this:
if ( IDVault.DNcompare(flowdata.get('Activity3/CardRequest/Candidate'),recipient )) true; else false ;
This comparison is case-insensitive. For example, the following DNs, when compared with DNCompare, would return True:
CN=jdoe,ou=users,ou=idmsample,o=acme cn=JDOE,ou=users,ou=idmsample,o=acme
The approach to handling errors differs between pre-activity and post-activity maps. For post-activity maps, you can use an error flow path from an Approval or Condition activity to catch errors that occur during post-activity mapping. This approach doesn’t work for pre-activity maps because any errors that occur in the process of getting data happen before the form is displayed to the user. When this occurs, an error message similar to the following appears in place of form controls in the bottom portion of forms displayed to the user:
XXXX FAILED to generate form due to: No data items are available!
In this scenario, you can use a try-catch statement in a source expression for a field in a pre-activity map:
function getTheData() { var theData; try { theData = IDVault.get( 'cn=jsmith,ou=users,ou=idmsample1,o=acme' , 'user', 'FirstName') + ' ' + IDVault.get ( 'cn=jsmith,ou=users,ou=idmsample1,o=acme' , 'user', 'LastName'); } catch (error) { theData = 'Error retrieving data.'; } return theData; }; getTheData();