> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sample 3. Step 9: Describing the Invoice Date field with grDate, InvoiceDate, and InvoiceDateAsString elements

> Describe the Invoice Date field with grDate, InvoiceDate, and InvoiceDateAsString elements, adding a Character String fallback for poor quality scans.

Analysis of the test images reveals that the Invoice Date field is located to the right of its name and on the same horizontal level as the name. Use a [Date](/flexi-capture/fls/template/date) element to look for the date. For poor quality images where dates may not be recognized properly and the search for the Date element gives no results, create an additional element of type [Character String](/flexi-capture/fls/template/character-chain). To specify the properties common to all these elements, create a compound grDate element.

To create the grDate element:

1. In the **InvoiceHeader** element, create an element of type [Group](/flexi-capture/fls/template/elements-compound) and name it **grDate**.
2. Click the Relations tab.
3. Since all the elements used to detect the Invoice Date field may only occur to the right of the keywords of the kwInvoiceDate name and on the same level as the name, set the following search constraints:
   * Right of the element **kwInvoiceDate**, Offset = 0.
   * Above the element **kwInvoiceDate**, Offset = -10, Element boundary = Bottom.
   * Below the element **kwInvoiceDate**, Offset = -10, Element boundary = Top.

<Frame>
  <img src="https://mintcdn.com/abbyy/8aWHPAJyzWmTqglX/images/flexi-capture/fls/tutorial3_9_1.png?fit=max&auto=format&n=8aWHPAJyzWmTqglX&q=85&s=b8a549b777e1dab310616794a9f1a470" alt="Screenshot of the Relations tab of the Properties of SearchElements.InvoiceHeader.grDate dialog box in ABBYY FlexiLayout Studio, showing the RightOf, Below, and Above relations to the kwInvoiceDate element." width="431" height="455" data-path="images/flexi-capture/fls/tutorial3_9_1.png" />
</Frame>

To create the InvoiceDate element:

1. In the `InvoiceHeader.grDate` element, create an element of type [Date](/flexi-capture/fls/template/date) and name it **InvoiceDate**.
2. Click the Date tab.
3. On the Date tab, specify all the possible date formats which may occur on the images. Assume that the date format is Day, month, year, the language is English, and there are no other constraints on the date.

<Frame>
  <img src="https://mintcdn.com/abbyy/8aWHPAJyzWmTqglX/images/flexi-capture/fls/tutorial3_9_2.png?fit=max&auto=format&n=8aWHPAJyzWmTqglX&q=85&s=2517c3f94b9000ce291c52ff20731544" alt="Screenshot of the Date tab of the Properties of SearchElements.InvoiceHeader.grDate.InvoiceDate dialog box in ABBYY FlexiLayout Studio, showing the Day, month, year format selected with English chosen as the date language." width="431" height="455" data-path="images/flexi-capture/fls/tutorial3_9_2.png" />
</Frame>

1. Click the Advanced tab.

2. Since the **Invoice Date** field is optional on this document but whenever it occurs, it occurs with its name and is always located next to the name, set the following [additional search constraint](/flexi-capture/fls/template/advanced-constraints) in the Advanced pre-search relations field: Look for the object on the image only if the **kwInvoiceDate** element has been detected; Look for the image object closest to the **kwInvoiceDate** element. In the [FlexiLayout language](/flexi-capture/fls/code/general-code):\
   `If InvoiceHeader.kwInvoiceDate.IsNull Then DontFind;`\
   `Nearest: InvoiceHeader.kwInvoiceDate;`

   <Tip>
     The **Nearest** constraint can also be specified via the program’s graphical user interface. Click the **Relations** tab, select **Nearest**, and in the **To:** drop-down list select **Element** and specify **kwInvoiceDate** as the **Reference element**.
   </Tip>

3. Try matching the FlexiLayout with the test images and make sure that the program successfully detects the element on all the images where there is an **Invoice Date** field.

When you test, you will see that on some of the images the element has not been detected. Analysis of the pre-recognition results reveals that this has happened because of the noise in the area of the field. None of the standard properties of the [Date](/flexi-capture/fls/template/date) element can be used to remedy the situation, so you must create an alternative element with less stringent search constraints.

<Note>
  For more information on finding dates on poor quality images, see [Date search after high or low-quality recognition](/flexi-capture/fls/tips-tricks/date2).
</Note>

To create the InvoiceDateAsString element:

1. In the `InvoiceHeader.grDate` element, create an element of type [Character String](/flexi-capture/fls/template/character-chain) and name it **InvoiceDateAsString**.

2. Click the Character String tab.

3. In the Character count field, specify this fuzzy interval: `{-1, 8, 14, INF}`, which is an estimate of the string length. Assume that the string may be 8 to 14 characters long. Any hypothesis outside this range will be penalized.

4. Set the Max space length to 20, which means that the space may be 20 dots long.

5. For the other properties, leave the default values.

6. Click the Advanced tab.

7. Since the program must look for this element only if the **InvoiceDate** element has not been detected, set the following [additional search constraint](/flexi-capture/fls/template/advanced-constraints) in the Advanced pre-search relations field: Look for the object only if the **InvoiceDate** element has not been detected. In the [FlexiLayout language](/flexi-capture/fls/code/general-code):\
   `If Not InvoiceDate.IsNull Then DontFind;`

8. Since the **Invoice Date** field is optional on this document but whenever it occurs, it is always present with its name and located next to the name, set the following [additional search constraint](/flexi-capture/fls/template/advanced-constraints) in the Advanced pre-search relations field: Look for the object on the image only if the element **kwInvoiceDate** has been detected; Look for the image object closest to the **kwInvoiceDate** element. In the [FlexiLayout language](/flexi-capture/fls/code/general-code):\
   `If InvoiceHeader.kwInvoiceDate.IsNull Then DontFind;`\
   `Nearest: InvoiceHeader.kwInvoiceDate;`

   <Tip>
     The **Nearest** constraint can also be specified via the program’s graphical user interface. Click the **Relations** tab, select **Nearest**, and in the **To:** drop-down list select **Element** and specify **kwInvoiceDate** as the **Reference element**.
   </Tip>

9. Try matching the FlexiLayout with the test images and make sure that the program successfully detects the element on all the images where there is an **Invoice Date** field and generates a null hypothesis for the **InvoiceDate** element.

10. To describe the location of the **InvoiceDate** block, select the Source element option, and then click <img src="https://mintcdn.com/abbyy/fmgRWFNHKYN2MLSg/images/flexi-capture/fls/Browse_Button.gif?s=3673db30dda4a3293aec716853588b55" alt="Browse button" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="21" height="20" data-path="images/flexi-capture/fls/Browse_Button.gif" /> and select the `InvoiceHeader.grDate` element as the source element.

<Note>
  The region of a [Group element](/flexi-capture/fls/template/elements-compound) is calculated by uniting the regions of all the detected subelements.
</Note>
