Versions Compared

Key

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

Table of Contents

Business rules are added by editing your form or workflow. Click the Rules editing mode in the Form/Workflow Designer header to add new business rules or edit existing ones.

...

  • Your new rule is given a randomly generated name. Change the name and description to describe the rule function.
  • Click the Run Builder button to open the Visual Rule Builder (Click the link to find out more information about the wizard) or the RuleDebuggingRuleDebugging button (Click the Rule Code link for details about the Rule Validator) button to enter the JavaScript directly. 
  • Click any  icon to edit an existing rule in the Visual Rule Builder.
  • Use the  Action Menu to
    • Collapse or expand the rule (you can also collapse/expand by clicking on the rule name or the carrot.)
    • Delete a rule. Confirm your choice in the dialog that pops up and the rule will be immediately removed. This is an irreversible process so make sure you do not need the rule before you delete it.
    • Enable /Disable  the rule. Rules are enabled by default. 
    • Move a rule to reorder the list. Depending on the rules current location your choices may be "Move up," "Move down," "Move top," and/or "Move bottom." You may also reorder rules by dragging and dropping them to another spot in the list.
  • Click Working with Rules1069515451 to see a readonly view of the javascript for all the rules in your form/workflow.
  • Click Save and Test  to test your rule without leaving the Rule Editor.

...

  • form.load : This event is occurs when a form or workflow step loads for the first time. It is useful for setting default values via rules that you need to be set before the user starts interacting with the form. 
  • form.unload : This event is true when users click the form's Submit or a workflow's Continue button. It is useful for setting control values just prior to the execution of the form's Doc Actions and Form Actions. If you have a rule in your form that changes any control(s) after clicking Submit, thereby making the form invalid, the form will no longer be submitted and the invalid form will redisplay. Form and Document actions will not execute,  PDFs are not generated, invalid controls become highlighted as expected and form.unload output displays in the DebugConsole Debug Console. This prevents an invalid xml for a successful submission from being created and only applies to forms.
  • form.positionUpdated : This event is used for the Geo location feature. You can fire a rule using this special identifier every time the position is updated.
  • form.activate: This event indicates that a workflow has navigated to a step. If form.activate is true, the workflow just moved to a step. Use the ExecuteaRuleonaSpecifiedWorkflowStep _data.getParameter to determine what step that is.
  • form.deactivate:  This event indicates that a workflow has left a step. If form.deactivate is true, the workflow just left a step. Use the ExecuteaRuleonaSpecifiedWorkflowStep _data.getParameter to determine what step that is.

form.load vs form.activate

...

Every control has a Properties icon. Click the "+" to expand the Properties. You will see a list of all the properties that are applicable to this control. Note that even the "form" itself has a Properties icon which show that the form has form.load and form.unload properties. LoanNumber is a quantity control and thus has all the properties you expect for this control type such as LoanNumber.required, value, visible, etc.

Refer to RuleEditorFunctions Rule Editor Functions for an alternative method of composing rules within the rules editor.

...

When you are designing a form/workflow with many objects and a lot of business rules, reduce the number of page reloads when switching between the designer view, rules view, and the test view by clicking the  save and test icon. Save and Test checks for Rule errors before the test popup displays. If rule validation errors are detected, the designer is notified and given the option to correct before the Test popup is displayed.

...

The validator also supports global directives. Use the global directive to identify additional global objects and functions defined in the execution environment and made available to the rule for which it is not appropriate to include a var statement in the rule code itself. One directive can be used to list all additional globals on a single line. Currently there are no known cases requiring the use of the global directive.  

Rule Editor Functions

The Rule Validator includes an enhanced editor designed to provide an easy experience when developing rules. The rule editor box includes the following features:  

FeaturesDescription
Line NumbersLine numbers in the rule code editor make it easier to correlate reported validation errors with the line of code.
Bracket auto closeType a {, ( or [ and the closing bracket is automatically inserted.
Match BracketPlace the cursor on a bracket and both it and the matching bracket are shown in a matching distinctive color (green).
Syntax Hi-lightingJavaScript syntax hi-lighting with keywords, variables, comments, etc. shown in distinctive colors.
Auto IndentNew lines are auto-indented according to generally accepted code formatting rules.
Code Folding
Bracketed code blocks (functions, if-then-else blocks, etc.) are collapsible. Click the arrow immediately to the right of the line numbers to collapse/expand code blocks.
Full screen edit mode

Expand the editor to full screen mode if you need more space to work. Click the "double arrow" expand icon (directly above the editor box) or press F2 when your cursor is inside the Rule box to expand to full screen. The ESC key returns you to small window mode.

Auto Complete/Hinting
When composing a rule, the designer can pick from a list of available frevvo controls and their properties directly within the rule editor. The pick list is context sensitive and will behave differently based on where the cursor is located when it is invoked. When on a blank space or immediately following an open bracket/brace, it can be manually invoked using Ctrl-Space to bring up a list of controls. Typing a dot (.) immediately after a frevvo control name or after the index ("[i]") that follows a control name will automatically bring up a context sensitive pick list of properties applicable to that control for selection. You can type the first letter of the item you are looking for and the property starting with that character will be highlighted in the list. Continue typing and the matching options will progressively narrow to the characters typed. Double click your choice using the mouse or press the Enter key to select an item. Any other key dismisses the pick list. . See the example AutoComplete/HintingExample 1069515451
HelpThe help icon displays a small help window listing the hot keys described above - (F2, ESC and Ctrl-Space)

...

The easiest way to minimize mistakes in control names when writing rules is to use the Auto Complete/Hinting feature in the rule editor. Let's say you want to compose a rule that will populate the FirstName field in your form with the first name of the logged in user when the form loads. This rule using the frevvo Built-inDatain Data in conjunction with the AccessingControlProperties form.load rule identifier will accomplish this.

...

Press the Enter key to advance to line 2. Add the left curly bracket. Press the Enter key to advance to line 3. Press Control Space. A list of available controls from your form will display. You can type the first letter of the item you are looking for and the first field name starting with that character will be highlighted in the list. Be sure to use the correct case. Double click or use the the Enter key to select the FirstName control. The control named FirstName will be inserted in your rule.

...

Add the remainder of the rule. The closing bracket will already be there. Of course, you can still use the UsingtheFormOutline 1069515451 to help you when composing rules.

...

This example shows a CUSTOM event. These events are created by adding frevvo.log() calls to your rules. Custom log messages are useful when you need even more debugging output. See Custom Logging for more details.

Note

Doc URI write methods information, which occur when the form is submitted, do not appear in the debug console output.

...

Rule execution can be profiled to determine how much time each rule takes to execute. This can help you tune and improve performance in forms that use a lot of business rules. To turn on profiling in the log files set the rule-debug=INFO or higher. See RuleDebugging Rule Debugging for setting log levels. Profiling output is also displayed in the Debug Console.

...

The minOccurs and maxOccurs (Max#) properties of a Table or Repeat control, can be used to write a rule to dynamically change Min# and Max# values of repeating items. This feature is helpful if you want to allow only a certain number of items based on user input. Here's how it works:

...

This is one case where the order of your rules matters. When adding rows, set the maxOccurs first, then minOccurs. When deleting rows, set minOccurs first, then maxOccurs. If you attempt to set minOccurs higher than the current maxOccurs, you will see an error in the debug console, "Illegal value for minOccurs. The type specifies a range of [0,3]. Attempted to set to: 4". Notice the rule order in these code snippets from this example rule to dynamically set min/max on a table.

Code Block
//Add new rows if existing number of rows is less than resultset length
  RepeatRow.maxOccurs = x.resultSet.length;
  RepeatRow.minOccurs = x.resultSet.length;

//Delete extra rows if existing number of rows is more than resultset length
  RepeatRow.minOccurs = x.resultSet.length;
  RepeatRow.maxOccurs = x.resultSet.length;

A common example is a form that retrieves data from a database - let's say the details of a Purchase Order. There could be one or more rows in the result. Depending on how many rows are returned, you may want to show only that many repeat/table rows in the form. Your rule can automatically set the min and max properties of the repeat/table to the same value (Min# = Max#) so that only the number of items specified in your rule are displayed. 

Refer to this rule example for repeats and this rule example for tables.

Info

When you dynamically populate repeats/tables using the Doc URI Approach, frevvo will automatically set the minOccurs/maxOccurs accordingly, so you do not need a business rule.

Note: Setting the min and max to the same value via a business rule will not always remove the left +/- column. You may see a blank left column.

Note

Please note that scaling tables or repeating sections via business rules when there are 100 rows or more may impact performance.

Selection Controls

Radio controls, dropdowns and checkboxes are all examples of select controls. Radio & dropdown controls are single select.  That is, if one item in the dropdown is selected then all other items in the dropdown are deselected.  The same is true for a radio.  Only one radio button can be depressed at any time.  Thus the <ControlName>.value of radios and dropdowns are similar to the other input and output controls.  The value is a single item.

...

Reusing Data from a Web Service

The example above uses the database connector, which returns a clean json that doesn't cause any problems when it is copied into a text field. The json returned from other services might included extra spaces or other characters and might require trimming. This can cause an error such as 'SyntaxError: Unexpected token in object literal'.

You may need to add this code, which removes spaces from the json string, to your first rule:

Code Block
​var json = http.get(requestUrl);
jsonUserData.value = json.replace(/[\n\t\r]/g,"");

...

  1. FirstName.value - only for parameters bound to a control in your form.
  2. {FirstName} - only for parameter used in http get TemplatizedURIs templatized URIs.
  3. _data.getParameter('FirstName') - if used anywhere else in a rule other than a URI.

...

LDAP supports both the standard subject attributes and custom attributes. When a user is successfully authenticated by the LDAP security manager, frevvo automatically retrieves Last Name, First Name and Email Address for this user from the LDAP server. You can retrieve custom attributes in addition to the standard ones from Active Directory and pull the data into your form/workflow using frevvo business rules. 

Rules can use Builtbuilt-inMethodsin methods to populate controls on a form/workflow with the information for the logged in user. The rules use the frevvo  _data.getParameter syntax, For example, the business rule shown fills the respective form fields with the First/Last Names and Email Address of the logged in user. 

...

Attributes with more than one value are also supported. For example, The carLicense attribute can return multiple licenses. You can write a rule to populate dropdown options with those values. Make sure the carLicense attribute is added to the custom field on the LDAP Configuration screen and of course, there are multiple carLicense attributes, each one containing a different value for the dropdown options, set up for appropriate users on the LDAP server.

...

If these methods are used in rules a the designer will see a message in the DebugConsole 1069515451 urging that the methods listed DateandTimeMethods 1069515451 be used instead.

Note

When you Save & Test a form, the form time zone is determined automatically. However, when you copy the share URL, you should consider whether to add the _formTz parameter to specify the time zone where the rules should run. 

  • When using frevvo.currentDateTime() or now() to set a Date/Time Control value without the _formTz parameter, these functions will return the current date/time in UTC and display it in the user's browser timezone. Often, this is the desired behavior, so _formTz is not necessary.
  • When using frevvo.currentDate() or today() to set a Date control value, or frevvo.currentTime() or timeofday() to set a Time control value without the _formTz parameter, these functions will both return and display the current date/time in UTC. This may or may not be the desired behavior, as the UTC time may appear "wrong" to the end user since it does not match their own time zone.
  • To return and display Date, Time, and Date/Time values set by these functions in a particular time zone, specify a timezone using the _formTz=<timezone> URL parameter.

See the Time Zones and Business Rules documentation for more details.

...

Here is a snippet of debug console output. The frevvo.log() message Event type displays as "CUSTOM". In this example the rule called the method frevvo.log('ERROR', 'Loading tenant roles...'); The message appears in red because all ERROR level log messages automatically are colored red.

See the DebugConsole 1069515451 topic for full details of all the console output information.

...