> ## 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 4. Step 9.2: Total Amount field, TotalAmount element

> Set up the TotalAmount Character String element in FlexiLayout Studio Sample 4, restricting its search area with advanced pre- and post-search relations.

Search for the **TotalAmount** field both to the right of and below its name.

## Create the TotalAmount element

<Steps>
  <Step title="Create the Character String element">
    In the **SumGroup** element, create a [Character String](/flexi-capture/fls/template/character-chain) element and name it **TotalAmount**.
  </Step>

  <Step title="Specify the alphabet">
    Click the **Character String** tab and specify the alphabet:

    `',-.0123456789OSZosz`
  </Step>

  <Step title="Set the non-alphabet character percentage">
    Set **Percentage of non-alphabet characters** to 30%.
  </Step>

  <Step title="Set the character count">
    In the **Character count** field, specify the fuzzy interval `{-1, 1, 20, INF}`, which assesses the string length. Assume that all possible values fall in the range of 1 to 20 characters. Any hypothesis outside this interval is penalized.
  </Step>

  <Step title="Keep the other defaults">
    Do not impose any additional constraints, and keep the default settings.
  </Step>

  <Step title="Exclude the kwTotal region">
    Click the **Search Constraints** tab and exclude the region of the hypothesis for the **kwTotal** element from the search area.
  </Step>

  <Step title="Add pre-search relations">
    Click the **Advanced** tab. In **Advanced pre-search relations**, specify additional search conditions. If the **kwTotal** name is detected, specify the search area as an array of rectangles, one to the right of the field name and one below it with some offset. Otherwise, do not search for the image object. In the [FlexiLayout language](/flexi-capture/fls/code/general-code):

    ```text theme={null}
    If not kwTotal.IsNull Then
    // If the field name kwTotal has been detected
    {
    WholeWordMode: true;
    MaxGapInLine: 30dt;
    RectArray DataRegion;
    Let r1= Rect (kwTotal.Rect.Right, kwTotal.Rect.Top -20dt, kwTotal.Rect.Right + 1800dt, kwTotal.Rect.Bottom + 50dt);
    // Limits the search area to a rectangle to the right of the field name.
    Let r2 = Rect (kwTotal.Rect.Left - 100dt, kwTotal.Rect.Bottom, kwTotal.Rect.Right + 100dt, kwTotal.Rect.Bottom + 200dt);
    // Limits the search area to a rectangle below the field name.
    DataRegion = RectArray (r1);
    DataRegion.Add (r2);
    RestrictSearchArea (DataRegion);
    }
    else Dontfind();
    // Otherwise, do not search for the object.
    ```
  </Step>

  <Step title="Add post-search relations">
    The search area for the field value is limited to two rectangles, one to the right of the field name and one below it. When the field value is to the right of the name, there is usually some text below the name. Because this redundant text falls in the search area for the **TotalAmount** field, FlexiLayout Studio creates a hypothesis for it.

    To lower the quality of this hypothesis, specify an additional check in **Advanced post-search relations**. The lower the field value sits below the field name, the greater the penalty. In the [FlexiLayout language](/flexi-capture/fls/code/general-code):

    ```text theme={null}
    If not IsNull then
    {FuzzyQuality: 400dt - width, {-50000,0,0, 50000}*dt;
    //Hypotheses for elements with region 400 dots wide will have the maximum quality
    if width < 50dt then Quality: 0;
    // Elements less than 50 dots are not considered
    if Top > kwTotal.Rect.Top then
    { FuzzyQuality: Top - kwTotal.Rect.Top, {0,0,0, 20000}*dt;
    }
    }
    //This check means that the higher the difference, the greater the penalty.
    ```

    <Info>
      To describe object locations and the distances between them, FlexiLayout Studio uses a two-dimensional coordinate system. The (0, 0) point is in the top left corner of the image. The horizontal axis runs left to right, and the vertical axis runs top to bottom.
    </Info>
  </Step>

  <Step title="Match the FlexiLayout">
    Match the FlexiLayout on the images to confirm that FlexiLayout Studio reliably detects the element on all the images where it occurs.
  </Step>

  <Step title="Set the block region">
    Specify the location of the **TotalAmount** block as the rectangular region of the **TotalAmount** element expanded by 5 dots vertically and horizontally. Select **Expression** and specify this expression:

    ```text theme={null}
    Rect outputRect;
    outputRect = SumGroup.TotalAmount.Rect;
    IsNull = SumGroup.TotalAmount.IsNull;
    OutputRegion = outputRect;
    OutputRegion.Inflate (5dt, 5dt);
    ```
  </Step>
</Steps>
