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 theDontfind() 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 theDontFind() 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 theGroupSample.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:
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: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.