Skip to main content
When a Group element is created, the Optional element box is clear by default, that is, the element is required. During FlexiLayout matching, a non-null hypothesis is generated for a required Group element, even if null hypotheses are generated for all of its subelements. To check the properties of the subelements of such a hypothesis, call the code in their Advanced sections. If the Group element is optional, a null hypothesis can be generated for it (if there are no non-null hypotheses with the quality higher than the quality of a null hypothesis).

Why calls to an undetected optional group fail

Avoid selecting the Optional element box for Group elements. The reason is that if the Group element is marked as Optional element and is not detected (its quality is lower than the quality of a null hypothesis, or the Dontfind() function is called for it), any call to any of its subelements will cause errors. This is because in a group with a null hypothesis, the hypotheses of subelements are not formed. To avoid this error, you must first check the Group element. If the IsNull check returns True, do not address any of the subelements.

When an optional Group element is useful

An optional Group element and its null hypothesis are needed when the entire group of fields is not present on the image, so searching for them serves no purpose. You can speed up the search for the elements by calling the DontFind() method for the Group element.
Here, “call” means writing code in any of the sections on the Advanced tab or in the block properties in the Expression window. If the properties of a Group element are called when setting the search constraints in Relations, the IsNull check is automatic. You can see this if you click Code on the Advanced tab.

The GroupSample.fsp sample project

This is illustrated in the GroupSample.fsp project (folder %public%\ABBYY\FlexiCapture\12.0\Samples\FLS\Tips and Tricks\Optional Group). In the Properties dialog box of the Group element InvoiceRequisiteGroup, the Optional element box is selected. On the Advanced tab, the Advanced pre-search relations section contains the following code:
This code checks for the presence of the element which identifies the document type. The FormID element, created before the Group element InvoiceRequisiteGroup, searches for the static text with a known value (“ID2015”). If the value of the identifier on the document matches the value specified in the Search text section, a non-null hypothesis is generated for the FormID element. Otherwise, the static text FormID is not detected, and FlexiLayout Studio is instructed not to look for the Group element InvoiceRequisiteGroup. In that case, a null hypothesis is created for the optional Group element InvoiceRequisiteGroup. The project contains an element TotalSumHeader that is used to look for the name of the sum field. The following code is entered for the element in the Advanced pre-search relations section:
This code means that the search for the name will be run below the date field described by the InvoiceDateHeader element, which, in turn, is a subelement of the Group element InvoiceRequisiteGroup.

Reproduce and fix the undefined hypothesis error

Run the FlexiLayout matching procedure on both pages in the batch. For page 1 the procedure is successful, but when the FlexiLayout is applied to page 2, FlexiLayout Studio displays the following error message:
This happens because on page 2 the value of the document identifier is ID 2589. Since this value is different from the one specified in the properties of the FormID element, the Dontfind() function generated a null hypothesis for the Group element InvoiceRequisiteGroup. As a result, the code called a non-existent hypothesis. The correct code must look like this.
If you comment out the code in the Advanced pre-search relations section and select the check box next to the similar search constraint of the TotalSumHeader element in the Relations section, clicking Code on the Advanced tab will show that the compiled code already contains the IsNull check.