Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Rules are probably best described by using examples. This chapter contains numerous real world samples.

...

You have a form with three controls and you have assigned them Names N1, N2 and T respectively. When the user enters a value in either N1 or N2 you want to set the value of T to the sum of N1 and N2. The rule would be written as

Code Block
languagejavascript
themeConfluencelanguagejavascript
T.value = N1.value + N2.value;

...

Show/Hide Manager Approval

You have a flow and the first form has a Section for manager approval. The Section is hidden by default. Here is an example of a rule that makes the section visible in the second step of the flow which is a linked activity assigned to the manager role. 

Code Block
if (form.load) {
  var an = _data.getParameter ("flow.activity.name");
  if (an === 'Manager' || an === 'VP'){
    ManagerApproval.visible = true;
  } else {
    ManagerApproval.visible = false;
  }
}

...

The 1st rule "Load Products" populates both the visible and hidden dropdowns with options from a database.

Code Block
/*member descriptionproductCode, productIdproductName, resultSet */
var x;
  
if (form.load) {
  eval('x=' + http.get('httphttps://localhost:8082app.frevvo.com/database/productsBIRT/allProducts'));   
 
    var opts1 = [];
     var opts2 = [];
 
     for (var i=0; i < x.resultSet.length; i++) {
         if (x.resultSet[i]) { 
            opts1[i] = x.resultSet[i].descriptionproductName;
             opts2[i] = x.resultSet[i].productIdproductCode;
        }
    }
 
  
Products.options = opts1;
  PID.options = opts2;
  Products.value = opts1[0]; // default to 1st product option
  PID.value = opts2[0]; 
}

Finding a Selected Options Index

...

Code Block
languagejavascript
if (Products.value.length 
> 0)

{
     var i; 
    for (var x in Products.options) {
        if ((Products.value + '=' + Products.value) === Products.options[x]) {
            i = Products.options.indexOf(Products.options[x]);
        }
    }
 
  PID.value = PID.options[i] + ''.split('=')[0];

}

In v4 rules using hidden dropdowns to keep descriptive option labels visible to the user while keeping cryptic database values hidden are often no longer necessary. Dropdown options have values distinct from the human visible option labels. The above can now be achieved with a single simpler rule:

...

Code Block
FirstName[0].label = 'blah label';
FirstName[0].hint = 'blah hint';
FirstName[0].help = 'blah help';

Clearing Values in a Table

This rule clears the values from all rows in a table. Notice the For loop that iterates over all the rows. Inside the loop a null value is assigned to all the columns in the table row.

Code Block
languagejs
for (var i = 0; i < Col0.value.length; i++) { 
    Col0[i].value = null;
    Col1[i].value = null;
    Col2[i].value = null;
  } 

You cannot clear an entire table from a rule.

Note

A section in a repeat will behave differently than a table row when using a rule to set the valid property. For Example, drag and drop a table control into your form. Name it T. Then drag and drop a section into the same form. Name it S. Add a control to the section. Name the control C. Drop the section into a repeat named R. Add this rule to the form.

Code Block
if(form.load){
 S[0].valid = false;
 TItem[0].valid = false;
}

The section header shows "Invalid value" as a message while the table row shows no such indication signifying an invalid row.

...

Code Block
if (form.load) { 
    if (_data.getParameter('flow.activity.name') === 'Manager Review') { 
Review.visible = true; 
    } 
} 

...

form.unload

Rules can be used to finalize field values after the users clicks the form's submit button but prior to the Form and Doc Action execution. Rules using form.unload are triggered when the form user clicks the submit button and for workflows when the user clicks continue to go to the next activity or finish to complete the flow.

...

A rule can dynamically display an image uploaded to your form via the upload control. In this example the upload control is named 'u'. The form also must contain a message control as a place holder for displaying the uploaded image. The rule dynamically creates a URL to the uploaded image in the temporary attachment repository. The upload control's value 'u.value' is a GUID that uniquely identifies the attachment. The uploaded image is included in the submissions pdf.

Code Block
languagejavascript
if (u.value.length > 0) {
  var baseUrl = _data.getParameter('_frevvo_base_url') + 
      ""/frevvo/web/tn/" +
      _data.getParameter('tn.id') +
      "/user/"+_data.getParameter('user.id') +
      "/app/"+_data.getParameter('app.id') +
      "/form/"+_data.getParameter('form.id');
 
  im.value = "'<img src="'" +
         baseUrl + "'/attachment/"' + u.value+"'/does_not_matter'"/>"';
} 

Here is the example form before and after the user has uploaded the orangegrove.png image:

...