> ## 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.

# Configure a custom Appian application to work with the ABBYY FlexiCapture Connector for Appian

> Configure a custom Appian application for the FlexiCapture connector by creating the AFC rules and the UploadDocument and CreateRecord Web API methods.

To enable a custom Appian application to interact with the ABBYY FlexiCapture Connector for Appian, create several entities. This page describes the two AFC expression rules and the two Web API methods that the connector requires. For the remaining entities, see [Modify the ABBYYFlexiCapture application](/flexi-capture/connectors/appian/appian-fc-app-modify).

<Info>
  Before you create these entities, make sure the `ABBYYFlexiCapturePlugin.jar` plugin is installed on the Appian server. To install it, copy the plugin from the connector distribution package into the `APPIAN_INSTALL/_admin/plugins/` folder.
</Info>

Create the following entities in order:

1. [Create a data type](/flexi-capture/connectors/appian/appian-fc-app-modify#datatype).
2. [Create a data source](/flexi-capture/connectors/appian/appian-fc-app-modify#datasource).
3. [Create a data store](/flexi-capture/connectors/appian/appian-fc-app-modify#datastore).
4. [Create a record type](/flexi-capture/connectors/appian/appian-fc-app-modify#recordtype).
5. [Create a constant of type Data Store Entity](/flexi-capture/connectors/appian/appian-fc-app-modify#datastoreentity) to link the data store to the data type.
6. [Create an AFC\_GetConstantDSEByRecordTypeName rule](#getconstantdsebyrecordtypename) that returns a constant of type **Data Store Entity**.
7. [Create an AFC\_GetDataTypeByRecordTypeName rule](#getdatatypebyrecordtypename) that returns the full name of the data type.
8. [Create a folder of type Knowledge Center](/flexi-capture/connectors/appian/appian-fc-app-modify#knowledgecenter) to store the processed files received from ABBYY FlexiCapture.
9. [Create the UploadDocument Web API method](#webapikc) to add a new document to the knowledge center.
10. [Create the CreateRecord Web API method](#webapidt) to populate the database table.

## <a id="getconstantdsebyrecordtypename" />Create an AFC\_GetConstantDSEByRecordTypeName rule

The `CreateRecord` method of the Web API requires a rule that returns a constant of type **Data Store Entity**. This rule determines the data store and data type where a record is created.

<Steps>
  <Step title="Create a new expression rule">
    In Appian Designer, open the application and click **New → Expression Rule**.
  </Step>

  <Step title="Name and save the rule">
    Select **Create from scratch**, complete the **Name** and **Save In** fields, and click **Create & Edit**.
  </Step>

  <Step title="Add the RecordTypeName input">
    In the **Rule Inputs** dialog box, click the **+** icon and add an input variable of type **Text** named `RecordTypeName`.
  </Step>

  <Step title="Paste the expression">
    In the code editor on the left, paste the following expression:

    ```text theme={null}
    if(ri!RecordTypeName == "New Records", /* In the RecordTypeName parameter, specify the name of the new record type in the plural.  */
        cons!New_Constant, /* After cons!, specify the name of the constant of the record type. */
        null /* If there is more than one record type in the application, replace "null" with the same "if" condition as above, specifying the name of the second record type and the name of its constant. */
    )
    ```
  </Step>
</Steps>

If the `RecordTypeName` input matches the name of a stored record type (in the plural), the rule returns the **Data Store Entity** constant that links the data store and the data type.

## <a id="getdatatypebyrecordtypename" />Create an AFC\_GetDataTypeByRecordTypeName rule

The `CreateRecord` method of the Web API requires a rule that returns the full name of the data type.

<Steps>
  <Step title="Create a new expression rule">
    In Appian Designer, open the application and click **New → Expression Rule**.
  </Step>

  <Step title="Name and save the rule">
    Select **Create from scratch**, complete the **Name** and **Save In** fields, and click **Create & Edit**.
  </Step>

  <Step title="Add the RecordTypeName input">
    In the **Rule Inputs** dialog box, click the **+** icon and add an input variable of type **Text** named `RecordTypeName`.
  </Step>

  <Step title="Paste the expression">
    In the code editor on the left, paste the following expression:

    ```text theme={null}
    if(ri!RecordTypeName == "New Records", /* In the RecordTypeName parameter, specify the name of the new record type in the plural, the full name of the data type, and the namespace of the record type. */
        'type!{urn:com:appian:types}NewDataType',
        null
        /* If there is more than one record type in the application, replace "null" with the same "if" condition as above, specifying the name of the second record type. the full name of the data type, and the namespace of the record type. */
    )
    ```
  </Step>
</Steps>

If the `RecordTypeName` input matches the name of a stored record type (in the plural), the rule returns a string with the full name of the data type. Otherwise, it returns `null`. To find the namespace, open the data type in the ABBYYFlexiCapture application, and then click the name of the data type in the top-left corner to open the **Data Type Properties** window.

## <a id="webapikc" />Create the UploadDocument Web API method

<Steps>
  <Step title="Create a new Web API">
    In Appian Designer, open the application and click **New → Web API**.
  </Step>

  <Step title="Name the Web API">
    Enter `UploadDocument` in the **Name** and **Endpoint** fields, change **HTTP Method** to **POST**, and click **Create & Edit**.
  </Step>

  <Step title="Paste the code">
    Close the template selection dialog box, and then paste the following code into the code editor:

    ```text theme={null}
    with(
        local!value: http!request.body,
        a!httpResponse(
            statusCode: 200,
            headers: {},
            body: uploaddocument(local!value)
        )
    )
    ```
  </Step>
</Steps>

<Note>
  The `uploaddocument(String query)` method appears in the code editor only if the `ABBYYFlexiCapturePlugin.jar` file is in the `APPIAN_INSTALL/_admin/plugins/` folder. This method sends a JSON string with the file contents directly to the Java method you created and returns a JSON string with the ID of the folder where the document was placed.
</Note>

## <a id="webapidt" />Create the CreateRecord Web API method

<Steps>
  <Step title="Create a new Web API">
    In Appian Designer, open the application and click **New → Web API**.
  </Step>

  <Step title="Name the Web API">
    Enter `CreateRecord` in the **Name** and **Endpoint** fields, change **HTTP Method** to **POST**, and click **Create & Edit**.
  </Step>

  <Step title="Paste the code">
    Close the template selection dialog box, and then paste the following code into the code editor:

    ```text theme={null}
    with(
        local!value: cast(
            rule!AFC_GetDataTypeByRecordTypeName(http!request.queryParameters.RecordTypeName),
            a!fromJson(http!request.body)
        ),
        a!writeToDataStoreEntity(
            dataStoreEntity: rule!AFC_GetConstantDSEByRecordTypeName(http!request.queryParameters.RecordTypeName),
            valueToStore: local!value,
            onSuccess: a!httpResponse(
                statusCode: 200,
                headers: {
                    a!httpHeader(name: "Content-Type", value: "application/json")
                },
                body: a!toJson(
                    fv!storedValues
                )
            ),
            onError: a!httpResponse(
                statusCode: 500,
                headers: {
                    a!httpHeader(name: "Content-Type", value: "application/json")
                },
                body: a!toJson(
                    {
                        error: "There was an error writing to the data store"
                    }
                )
            )
        )
    )
    ```

    * `rule!AFC_GetDataTypeByRecordTypeName(http!request.queryParameters.RecordTypeName)` accepts a parameter with the name of the record type (received by the Web API method from the ABBYY FlexiCapture Connector for Appian) and returns the full name of the data type.
    * `rule!AFC_GetConstantDSEByRecordTypeName(http!request.queryParameters.RecordTypeName)` returns the **Data Store Entity** constant.
  </Step>

  <Step title="Add the query parameter">
    1. In the right-hand pane, click the **New Query Parameter** button and add a parameter named `RecordTypeName` to the query string.
    2. Select the **Set as default test value** option and click **Save**.
  </Step>
</Steps>
