Live Forms v6.1 is no longer supported. Click here for information about upgrading to our latest GA Release.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

Business Rules have several quirky behaviors that will be addressed in a future release. Please read and understand these points before writing your first business rule. 

Why do I need a local variable for certain cases ?

There are rules scenarios where you can't use a  control directly in a rule expression and you are forced to define a local variable, perform the computation using the local variable and assign the value to the control at the conclusion of the computation.

For instance, assume a form that calculates a total from a list of subtotals. The total is a control T and subtotals are represented as a repeat of controls S. In other words, T holds the total of adding all values in S. You could write the rules as:

T.value = 0; 
for (var i = 0; i < S.value.length; i++) {   
    T.value = T.value + S[i].value; 
} 

The code above makes logical sense but it just won't work. In a nutshell this particularity of the  implementation can be resumed this way:

The right hand side of an assignment expression resolves to the value of a  control passed to a rule when it is invoked. The left hand side uses a reference to the control'.

Lets work with a concrete example to understand the concept. Assume that there are two subtotals in the form, 12 and 14 and the total is correctly set to 26. Now, you add 50 as a third subtotal and the rule fires as a consequence. The values of the controls involved in the rule are passed as parameters to the rule: the subtotals 12,14 and 50 and the current total (value of T), 26. The core of the matter is in the expression:

T.value = T.value + S[i].value; 

The expression will be evaluated three times (since there are three subtotals) but for every iteration, the T.value operand on the right hand side will always evaluate to 26 which is not the desired behavior and will lead to an incorrect result. Again, this happens because the right hand side of that expression is resolved based on the values initially passed to the rule as parameters.

 explicitly imposes this restriction for the sake of efficiency and there would be a significant impact in performance if the restriction was not in place. Lets rewrite the rule using a local variable:

var tot = 0; 
for (var i = 0; i < S.value.length; i++) {   
    tot = tot + S[i].value; 
} 
T.value = tot; 

This rule will produce the expected result. 

Why does a commented out code line still execute?

A rule with a code line inside a comment block may still execute. For example this rule uses two different Javascript comment styles. The commented out lines in both cases will execute even though you would expect them to be ignored. Do not use comments for this purpose.

if (form.load)
{
  PO.value = 'A-234';
  // FN.value = 'Nancy';
  /* LN.value = 'Doe'; */
}

Why do my rules show unexpected results in a flow using Linked activities?

This question is best answered with an example. Let's say you have a two step flow that contains the following rules; When step 1 of the flow is execute, the form loads and the Sales Planner Status control displays "Not Ready for Review".

Sales Planner Status:
if (form.load) { 
   SalesPlannerStatus.value = "Not Ready for Review"; 
}

CP Status:
if (CP.value == "Yes") { 
  SalesPlannerStatus.value = "Ready for Review";
} else if (CP.value == "No") { 
  SalesPlannerStatus.value = "Not Ready for Review";
}	

If the user clicks Yes in the CP field, the Sales Planner Status control displays "Ready for Review"

When you click Continue to advance to the next step of the flow, the value of the Sales Planner Status is set to "Not Ready for Review" even though value of CP is still Yes.

This is as designed. The logic purposely ignores setting value properties that happen in a flow during form state initialization. This is what happens in the second step of this flow using linked activities. Note that changes to other attributes other than value are not ignored during initialization. The designer will see a message in the log and debug console output that says the set of the property value is ignored.

Adding if (_data.getParameter('flow.activity.name') == "Step 1") to the Sales Planner Status rule, gives the expected results:

What causes an "Invalid signature detected. Data may have been tampered with" error?

Business rules are not prevented from changing control values in signed sections. This error message usually displays in multi-step workflows when there is a rule on a subsequent step that executes at form load and updates values inside a signed section in a previous step. Here are some examples and solutions:

Example 1:Checkbox with Custom Options in a locked Signed Section

Imagine a two step workflow designed with Linked Steps where step 1 contains a Checkbox control inside a section that the user is required to sign, The checkbox has only one option defined in the flow designer.  A Business rule is executed when step 1 loads to dynamically populate the checkbox with additional options.


The image shows this scenario in use mode after the rule has executed. Notice there are three options for the checkbox now. The user selects all three options, signs then clicks continue.

The flow is routed to Tasks Lists of users who fulfill the requirements for the next step. When Step 2 loads, the rule is executed again. This combination results in data tampered error.

Solution:

This situation can be avoided by always setting more than one option in the flow designer for any checkbox that will be dynamically populated with a rule.

Example 2: Avoiding this error in Workflows

Another common situation where rules can update values in a signed section and make that section signature invalid can happen in workflows, especially if they are designed using Linked Forms in a Flow. Let's take a two step workflow where step 1 has a Number control inside a section that the user is required to sign. A rule to generate a unique case number is designed to run when when a workflow step loads. Here is a rule that uses the JavaScript Date valueof() function to generate a number and set a variable. The value of the Case Number control is then set to the value of n.

if (form.load) { 
  var n = new Date().valueOf().toString(); 
  CaseNumber.value = n; 
} 

When step 1 loads:

  • the rule will set the value of the Case Number control to some value.
  • the Section with the Case Number control is signed.

When step 2 loads:

  • The same rule will run again due to the linked step design and modify the Case Number control data.
  • Since the data has changed, the signature will show as invalid (tampered data).

 

Solutions:

Change the rule to prevent the value from being changed if there is already a value in the Case Number control in Step 1:

var n;
if (form.load && CaseNumber.value.length === 0) {
  CaseNumber.value = n;
}
or add a condition to the rule such that it executes only on step 1 of the flow. This rule uses the built-in method_data.getParameter('flow.activity.name') to detect the current step and uses it in the rule condition.

 

var n;
var an = _data.getParameter("flow.activity.name");
if (form.load && an === 'Step 1') {
var n = new Date().valueOf().toString(); 
  CaseNumber.value = n;
}

 

will prevent a rule from modifying a field that's inside a signed section in a future release.

 

  • No labels