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.

provides frevvo provides two ways to create business rules:

...

  • 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 Rule Code RuleDebuggingRuleDebugging button (Click the Rule Code link for details about the Rule Validator) 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 View AllWorking with Rules 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.

...

However, catching an exception when a  control a frevvo control does not exist (is undefined), will not work as you might expect. This is because  catches because frevvo catches the problem while parsing the rule before the JavaScript interpreter catches the error. In the example below the control named Color does NOT exist in the form.

...

It is very important when using a control in a rule that the control has a unique name. If multiple controls have the same name  can name frevvo can not determine which control the rule refers to. Controls added to your form from palette are for the most part forced to have a unique name. If you try to change it to a name of a control that already exists in your form  will form frevvo will not allow it. However there are several ways you can have multiple controls with the same name:

...

Rules refer to form controls using the control's Name. Refer to properties of the control using the syntax <Control Name>.<Property>.  frevvo supports the following properties:

  • visible : Set to false to hide a control and true to make the control visible.
  • value : Read or write the value of a control. This is not applicable to sections, tabs and other controls where it does not make sense to set a value.
  • enabled : Set to false to disable (grey out) a control so that a user can not change its value and true to enable it. This is not applicable to sections, tabs and other controls that do not make sense to disable/enable.
  • expanded : Set to false to collapse a group control (sections controls only) and true to expand a group control.
  • selected : Set to true to make a tab the selected tab (tab controls only).
  • valid : The value of this property is true if the control contains a valid value otherwise false.  Validity is based on the control’s type.  For instance a numeric control will be invalid if the user enters a string value that cannot be converted to a number.  This property can be read as well as written.
  • required : Set to true to make a control required and display a yellow background color. Available for palette and schema controls (controls generated from XSD schema data source). This is also a property of section controls. Setting a section required to false automatically sets all inner controls to not required. Click here for an example.
  • options : This property enables dynamic setting select control options (radio, dropdown & checkbox controls only).
  • label : This property sets the label seen on any control including sections.
  • help : This property sets the help text.
  • hint : This property sets the hint seen on hover.
  • status : This property sets the error message display whenever the control's value is invalid. The one exception is the Required Property for Controls in an Accessible form/workflow.
  • clicked : This property works with trigger controls.  Its initial state is false.  When a user clicks a trigger its state turns true.
  • printable: Set to false to remove the control from both the printable view and PDF submission document.
  • itemAdded : This property works with repeat controls.  Its initial state is false.  When a user clicks "+" to add a repeat item AND when a repeat item is added via a Document URI as the form loads its state turns true.
  • itemRemoved : This property works with repeat controls.  Its initial state is false.  When a user clicks "-" to delete a repeat item its state turns true.
  • itemIndex : This property works with repeat controls. When an itemAdded or itemRemoved event fires the value of itemIndex is set. For itemRemoved events itemIndex will return -1. For itemAdded events itemIndex will give you the index of the added item
  • minFiles - This property only applies to an Upload control. Use this property to dynamically change the minimum number of attachments that can be uploaded by the user.
  • maxFiles - This property only applies to an Upload control. Use this property to dynamically change the maximum number of attachments that can be uploaded by the user.
  • comment.value - This property only applies to dropdowns, checkboxes and radio controls. Use this property in a rule to retrieve or set the value of the comment field that displays when users select the last option. The comment value can also be accessed for dropdowns, check boxes and radios directly in templates using special syntax.

Examples of identifiers used in  rules in frevvo rules are:

  • FirstName.value
  • BillingAddress.visible
  • Email[1].value 
  • Email[i].visible

...

  • 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 debug console DebugConsole. 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 _data.getParameter ExecuteaRuleonaSpecifiedWorkflowStep 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 _data.getParameter ExecuteaRuleonaSpecifiedWorkflowStep 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 Rule Editor Functions RuleEditorFunctions for an alternative method of composing rules within the rules editor.

...

When you create or edit a rule,  figures  frevvo figures out the list of controls and properties of those controls that the rule depends upon. The rule will be automatically executed whenever there is a state change that is relevant to the rule. This is called a dependency. If there are multiple rules triggered by the same dependency, the rules are executed sequentially in a top to bottom order as they are seen in the form designer's rules panel.

...

It's easy to create rules that run forever. An example is a rule that updates A.value based on B.value and another rule that updates B.value based on A.value. They could continually trigger each other.

The  server The frevvo server will prevent this from happening by setting an execution time limit for each rule. Any rule that takes longer than 5 seconds to execute will be forcibly stopped. Note that this is a very lengthy period of time for most computational tasks and the vast majority of rules will not be impacted by this constraint. However, since  is since frevvo is a hosted site that may be simultaneously used by numerous users, there is a time limit imposed on these computations.

...

Business rules are executed on the  serverfrevvo server-side and not as client-side javascript. There are several reasons why rules execute server-side:

...

In general, it is not recommended to rely on either the browser's locale or the server's locale when writing date, time (time of day) and date/time literals in frevvo rules. The recommended method is to use locale independent formats that are listed below. These are standard ISO formats.

...

Time and date/time controls also require correct formatting and an understanding of how  manages how frevvo manages timezones.  converts  frevvo converts times into the browser's local timezone before displaying them in the form. However, if time data is not correctly formatted  will formatted frevvo will make multiple attempts to parse the time but will always display the time with NO timezone conversion. Here are examples of correct time formats:

...

The time control is independent of any timezone and simply displays the value as is. The time value should not shift no matter which timezone (or DLS effect) you are accessing it from.

 automatically frevvo automatically converts the displayed time for date/time controls to the browser's local time zone. There is no conversion for only date or only time controls. Here are some examples to clarify proper time initialization and expected displayed time. Also refer to the chapter Initializing Forms with Data for date, time and date/time controls.

...

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 controls 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  control 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 below AutoComplete/HintingExample
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-in DatainData in conjunction with the form.load AccessingControlProperties rule identifier will accomplish this.

...

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

...

  • # -  A sequential line number. The # starts at 0 when a form is instantiated and increments until the form is finally submitted. Even if you clear the console by clicking the Clear link, the numbers continue incrementing from where they left off for this particular form instance. This gives you a clear way to follow the order in which the rule code was executed during the lifetime of a particular form instance.  
  • Level - One of 5 log levels. See below for details. The level also dictates a color coding. For example all ERROR log level messages are displayed in red.
  • Event  - One of many possible Events. This column enables you to quickly distinguish between various events such as rule start/stop. See the detailed event list below.
  • Source - This column contains the name the designer gave to each rule for RULE_START and RULE_END events so that you can clearly see which rule the output lines are a part of. Source is also set for DOC_READ_START and DOC_READ_END events and indicates the name of the data source. If the data source is the default document Source displays the form/workflow's name. 

Refer to the  log the frevvo log files for a complete history of all rule debugging output. 

...

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 CustomLoggingMethods for more details.

Note

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

...

Rules debug output can also be written to the  log the frevvo log file <frevvo-home>/frevvo/tomcat/logs/frevvo.log file and is also visible in the tomcat console if tomcat stdout logging is enabled.

To change the rule debug logging verbosity level, append one of the URL parameters below to the  base the frevvo base URL. For example: http://<server:port>/frevvo/web?rule-debug=TRACE turns on the highest rule debug log level.  The verbosity options are:

...

Note

Changing the rule logging verbosity affects all tenants, users, and forms running on the serverfrevvo server. A high log level can effect the form server's performance. Turn rule logging back to the lowest level of ERROR when your are done debugging.

...

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 rule debugging RuleDebugging for setting log levels. Profiling output is also displayed in the Debug Console.

...

As rules are executed on the  server frevvo server and not on the browser client side. Thus timing is effected by the performance of your server machine and the server's current load.

...

By default a rule that takes longer to execute then 5 seconds will be timed out by the Form Server. Customers using the in-house download version can customize this timeout. This is often necessary when rules have to perform longer running operations such as sending email messages, database stored procedures, etc. To configure the timeout add the following line to your web application containers property file. For the frevvo-tomcat bundle this file is <frevvo-home>\tomcat\conf\Catalina\localhost\frevvo.xml and is specified as follows:

...

In the designer, set the min/max properties so that they cover the whole range of min and max numbers that you wish to use via rules. When you increase the Min# value with a rule,  will frevvo will check if that number of items are there in form, if not then it will add them. When you reduce the Max# via rule,  will frevvo will check if the form has more than that many number of items. If there are more items than the Max# that you are setting via rule, it will remove those extra items.

...

Every control in your form has an initial default property states for the visible, expanded, value, valid & enabled properties.  However you can change a controls initial state in in frevvo's form designer Edit tab.  A control’s initial state can be modified several ways.  One way is by simply typing a value into an input control.  This sets the default value for the control when the form is first opened in use mode.  Another way is by expanding or collapsing group controls.  This sets the initial expanded state.  The default state for the visible and enabled properties is set via the controls edit property panel.  The edit property contains checkboxes for visible and enabled for controls on which those properties make sense like input controls.

...

  1. the URL to the web service
  2. payload (data) constructed as a JavaScript object.
  3. headers constructed as a JavaScript object
  4. Whether the payload is in multipart form
  5. dataOnly, which defaults to true and returns just the content. It should be set to false in order to get additional information (headers, status) in a JSON format (see this sample JSON data set).

    Expand
    titleClick here for an example of the json response...

    If the dataOnly parameter is set to false, frevvo returns a JSON string with a content field containing data, header (another JSON object containing the headers), status code, and reason (describes the status). For example:

    Code Block
    {"content":"…", "header": {"Access-Control-Allow-Origin":"*", "Connection": "Keep-Alive", ...}, "statusCode":200, "reason":"Ok"}

     Not every HTTP method provides content. In case of an exception, a null is returned in all cases.

    Here is a sample business rule to illustrate the response:

    Code Block
    /*member statusCode, reason, content, header, Server*/
    var response;
    if (form.load) {
      eval('response=' + http.get('https://httpbin.org/json',null,true,false));
      if (response) {
        Status.value = response.statusCode;
        Reason.value = response.reason;
        Content.value = response.content;
        Headers.value = response.header.Server;
      }
    }



In previous versions of frevvo, the post, put, get and delete methods accepted only a JSON string for payload and header parameters. Using string concatenation to generate a JSON string is fragile due to potential encoding issues and possibly XSS security concerns. This requires the designer to use JSON.stringify('{name:'+Name.value+'}')) to avoid encoding issues.

...

  1. The rule will fail when executed if the object syntax is incorrect.
  2. takes frevvo takes care of encoding to JSON automatically.

...

When making http calls from rules, special characters (e.g #) cannot be used in URLs  because the URL which is passed in the http method gets encoded by default. For example, if the URL contains a #,  encoding  frevvo encoding assumes this is a query fragment. If the designer encodes it as shown in the example below by replacing the # with the encoded value %23,  will  frevvo will encode it again turning the % into %25 for a final value that looks like %2523. This returns an invalid URL.

A boolean parameter can be specified in a rule for http.get, http.put, http.delete and http.post methods that can be used to tell  not tell frevvo not to encode the URL. In this case, the designer  encodes the URL and sets this parameter to false to turn off additional encoding by by frevvo.

For example: Let's say you write a rule to perform an http get to a web server when the form loads. Here is the URL you want to use in plain text:

...

Code Block
if (form.load) {
  var url = "http://<your webserver:port>/Client/AMR/Vendors/aramark%7C8435%20Georgetown%20Road%23100IndianapolisIN46268";
  var response = http.get(url);
  frevvo.log(response);
}

 encodes frevvo encodes the URL again. The result is a server 404 error because the URL is invalid which prompts an error message in the  logfile the frevvo logfile similar to:

In this rule, the local variable URL is set to the encoded version and the http.get() includes the third argument, set to false, to prevent double encoding:

...

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,"");

...

The dynamic content described above requires an http get to a specific URI service returning a JSON object. The examples above specified absolute URI paths. You can also use a relative path.

Assuming the  Form the frevvo Form Server is running on http://www.myhost.com, http.get(‘http://www.myhost.com/path/to/resource’) may instead be written as http.get(‘/path/to/resource’).

...

In this example the path to the URI service is an absolute hard coded path. When the service is running on the same host as the  form the frevvo form server you may use a relative URI. One common scenario where this is applicable is for  Infor frevvo In-house customers who have also installed the  database the frevvo database connector. In this case the rule is best written as follows because it becomes portable if you move your form server from one <webhost> to another <webhost> as is common when running under development servers and moving to production servers.

...

URL parameters passed into your form via the _data  parameter  frevvo parameter can be accessed in rules several ways. If &_data(FirstName:'Joe') was added to your form URL, then:

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

Option 2 & 3 are available for both bound and unbound controls. So choose whichever approach is the simplest for you.

Built-in Data

 makes frevvo makes certain data available to your rules. This includes information about the person currently using your form, the tenant and form information. You retrieve this data in your rule using the _data.getParameter('<data name>') syntax. Here is the list of available data:

...

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  business using frevvo business rules. 

Rules can use builtBuilt-ininMethods methods to populate controls on a form/workflow with the information for the logged in user. The rules use the   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.

...

Note

The manager attribute maps to the builtfrevvo built-in data 'subject.reports.to.' This means you can retrieve this value in a rule or use 'subject.reports.to' for workflow navigation if you configure the manager attribute in your LDAP tenant.

...

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

Built-in Methods

 provides frevvo provides built-in helper methods for common functionality required by business rules.

...

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

Note

When you test a form in frevvo, the form time zone is determined automatically. Your form will load with the values specified in your rule. However, when you copy the share URL, you MUST append the formTz parameter. This is because the form server needs to know the time zone in which to return the date and/or time. 

If _formTz is not specified, here is how each function will behave:

VRB functionRule CodeBehavior if no _formTz specified
timeofday()frevvo.currentTime()Returns server time in UTC
today()frevvo.currentDate()Returns server date in UTC
now()frevvo.currentDateTime()Returns server date and time

Use ?_formTz=<time zone> string to add the time zone parameter directly after the form/workflow URL or &_formTz=<time zone> string to add the parameter after an existing URL parameter. For example, to specify the Eastern time zone as the first parameter after the URL use ?_formTz=America/New_York. Time zone strings can be found here. Refer to this documentation for more information.

...

Here is the list of methods that can be used in business rules to verify if a specified user or role exist in your tenant or if a tenant exists in your serverfrevvo server. These methods return a boolean true/false value:

...

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 debug console DebugConsole topic for full details of all the console output information.

...

JavaScript behavior when calculating decimal point addition, might show a result with a large number of decimal places. provides frevvo provides a built-in method, toFixed(n) that can be used in this situation.

...

This feature is mainly intended for OEM  partnersOEM frevvo partners. Often there are common rule code that is reused over and over in many forms. Traditionally this code must be duplicated in each form.  is  frevvo is packaged with a file in tomcat/webapps/frevvo/WEB-INF/rules/includes.js which is initially empty. OEM  partners OEM frevvo partners can put commons functions into includes.js. There is a second file com.frevvo.forms.model/src/main/resources/com/gauss/forms/rule/executor/includes.js also in the WEB-INF directory whose contents are defined by frevvo.

When you write any form rule you can now call functions defined in these two includes.js files above. The first one is for OEM partners to create and repackage with frevvo.zip. The second one is frevvo's and is automatically updated when there is a new release and should not be modified by OEM partners.

...

Note that includes.js is parsed and compiled once when  startswhen frevvo starts. If you update this file with new functions and fixes to existing functions you must restart  for restart frevvo for the changes to take affect. 

...