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

# SendForProcessing activity for a single-document case

> Configure the SendForProcessing Pega activity for a single-document case: open the case, loop over the attachments, and call ABBYY FlexiCapture to start processing.

The `SendForProcessing` activity opens the case, sends the first attachment to ABBYY FlexiCapture, and stores the batch identifier and the verification URL that FlexiCapture returns.

For the general procedure, see [Create a Pega activity](/flexi-capture/connectors/pega/pega-activity-create).

## Pages and classes

| Page name        | Class                  |
| ---------------- | ---------------------- |
| `Case`           | `Work-`                |
| `Attachment`     | `Data-WorkAttach-File` |
| `AttachmentInfo` | `Data-WorkAttach-File` |

## Parameters

| Name     | Data type | Required |
| -------- | --------- | -------- |
| `CaseId` | `String`  | Yes      |

## Local variables

| Name          | Data type |
| ------------- | --------- |
| `LinkedRefTo` | `String`  |
| `Id`          | `String`  |
| `Index`       | `String`  |

## Activity steps

<Steps>
  <Step title="Open the case">
    | Field              | Value                |
    | ------------------ | -------------------- |
    | **Method**         | `Obj-Open-By-Handle` |
    | **Step page**      | `Case`               |
    | **InstanceHandle** | `Param.CaseId`       |

    <Frame>
      <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega105.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=acd7b1240f492e29286b5f2f456d2286" alt="Screenshot of step 1 in Pega configured with the Obj-Open-By-Handle method, the Case step page, and an InstanceHandle of Param.CaseId." width="928" height="279" data-path="images/flexi-capture/connectors/Pega105.png" />
    </Frame>
  </Step>

  <Step title="Reset the attachment counter">
    Set **Method** to `Property-Set` and the property as follows:

    | PropertiesName | PropertiesValue |
    | -------------- | --------------- |
    | `Local.Index`  | `0`             |

    <Frame>
      <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega106.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=ba893bb18d8502f0c3db8817817c988c" alt="Screenshot of step 2 in Pega configured with the Property-Set method, a PropertiesName of Local.Index, and a PropertiesValue of 0." width="1116" height="206" data-path="images/flexi-capture/connectors/Pega106.png" />
    </Frame>
  </Step>

  <Step title="Loop over the case attachments">
    Set **Method** to `Property-Set` and the properties as follows:

    | PropertiesName      | PropertiesValue                               |
    | ------------------- | --------------------------------------------- |
    | `Local.LinkedRefTo` | `Case.pyAttachments(<CURRENT>).pxLinkedRefTo` |
    | `Local.Id`          | `Case.pyAttachments(<CURRENT>).pzInsKey`      |

    <Frame>
      <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega107.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=defbfa4362a621026a9ff6e1c23dfff5" alt="Screenshot of step 3 in Pega using the Property-Set method, with Local.LinkedRefTo set to the pxLinkedRefTo of the current Case.pyAttachments element and Local.Id set to its pzInsKey." width="1120" height="238" data-path="images/flexi-capture/connectors/Pega107.png" />
    </Frame>

    Set the **Loop** properties as follows:

    | Repeat                         | Value List Property  |
    | ------------------------------ | -------------------- |
    | For each element in value list | `Case.pyAttachments` |

    <Frame>
      <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega108.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=dd14bd9d0c06edd5dbced9290efb887a" alt="Screenshot of the Loop dialog in Pega for step 3, with Repeat set to For each element in value list and the Value List Property set to Case.pyAttachments." width="470" height="169" data-path="images/flexi-capture/connectors/Pega108.png" />
    </Frame>

    Add the following **When** condition, so that only the first attachment is sent:

    | When             | if true        | true param | if false  | false param |
    | ---------------- | -------------- | ---------- | --------- | ----------- |
    | `Local.Index==0` | Continue Whens |            | Skip Step |             |

    <Frame>
      <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega109.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=4af0f2919dcb8e002014ed8ec0270bd2" alt="Screenshot of the When conditions dialog in Pega for step 3, with the condition Local.Index==0 set to Continue Whens if true and Skip Step if false." width="1001" height="235" data-path="images/flexi-capture/connectors/Pega109.png" />
    </Frame>

    Add the following substeps to this step, so that the loop repeats them for each attachment:

    1. **Open the attachment**

       | Field              | Value                |
       | ------------------ | -------------------- |
       | **Method**         | `Obj-Open-By-Handle` |
       | **Step page**      | `Attachment`         |
       | **InstanceHandle** | `Local.LinkedRefTo`  |

           <Frame>
             <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega110.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=cc92e748bf9483196a8f369a0ed2b065" alt="Screenshot of substep 1 in Pega configured with the Obj-Open-By-Handle method, the Attachment step page, and an InstanceHandle of Local.LinkedRefTo." width="1098" height="310" data-path="images/flexi-capture/connectors/Pega110.png" />
           </Frame>

    2. **Open the attachment information**

       | Field              | Value                |
       | ------------------ | -------------------- |
       | **Method**         | `Obj-Open-By-Handle` |
       | **Step page**      | `AttachmentInfo`     |
       | **InstanceHandle** | `Local.Id`           |

           <Frame>
             <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega111.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=e64a8844bd880700afe9c831f93d7ca0" alt="Screenshot of substep 2 in Pega configured with the Obj-Open-By-Handle method, the AttachmentInfo step page, and an InstanceHandle of Local.Id." width="1096" height="313" data-path="images/flexi-capture/connectors/Pega111.png" />
           </Frame>

    3. **Send the document to ABBYY FlexiCapture**

       Set **Method** to `Call-Function` and the function as follows:

       | Function                                                                     | Return value |
       | ---------------------------------------------------------------------------- | ------------ |
       | `@ABBYY.SendForProcessing(AttachmentInfo.pyMemo, Attachment.pyAttachStream)` | `.BatchId`   |

       For more information, see [SendForProcessing](/flexi-capture/connectors/pega/pega-func-one-doc#sendforprocessing).

       Add the following **Jump** condition, and set **On exception, jump to later step label** to `ERR`:

       | When             | if true            | true param | if false | false param |
       | ---------------- | ------------------ | ---------- | -------- | ----------- |
       | `StepStatusFail` | Jump to Later Step | `ERR`      |          |             |

           <Frame>
             <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega112.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=821342a9570521e6691c30f5f147f6b2" alt="Screenshot of substep 3 in Pega using the Call-Function method, with the function @ABBYY.SendForProcessing(AttachmentInfo.pyMemo, Attachment.pyAttachStream) and a return value of .BatchId." width="859" height="189" data-path="images/flexi-capture/connectors/Pega112.png" />
           </Frame>

           <Frame>
             <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega113.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=4add505d7eabcc578a43d5fa58d00fd7" alt="Screenshot of the Jump conditions for substep 3 in Pega, with a StepStatusFail condition that jumps to later step ERR if true and an on-exception label of ERR." width="998" height="279" data-path="images/flexi-capture/connectors/Pega113.png" />
           </Frame>

    4. **Wait for the verification URL**

       Set **Method** to `Call-Function` and the function as follows:

       | Function                                            | Return value       |
       | --------------------------------------------------- | ------------------ |
       | `@ABBYY.WaitFirstVerificationOrProcessed(.BatchId)` | `.VerificationUrl` |

       For more information, see [WaitFirstVerificationOrProcessed](/flexi-capture/connectors/pega/pega-func-one-doc#waitfirstverificationorprocessed).

       Add the following **Jump** condition, and set **On exception, jump to later step label** to `ERR`:

       | When             | if true            | true param | if false           | false param |
       | ---------------- | ------------------ | ---------- | ------------------ | ----------- |
       | `StepStatusFail` | Jump to Later Step | `ERR`      | Jump to Later Step | `INC`       |

           <Frame>
             <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega114.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=daf5a76f7855f2fdd079d94407995623" alt="Screenshot of substep 4 in Pega using the Call-Function method, with the function @ABBYY.WaitFirstVerificationOrProcessed(.BatchId) and a return value of .VerificationUrl." width="1083" height="235" data-path="images/flexi-capture/connectors/Pega114.png" />
           </Frame>

           <Frame>
             <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega115.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=764b540e078cd46fa1eecb32a45414dc" alt="Screenshot of the Jump conditions for substep 4 in Pega, with a StepStatusFail condition that jumps to later step ERR if true and INC if false, and an on-exception label of ERR." width="990" height="281" data-path="images/flexi-capture/connectors/Pega115.png" />
           </Frame>

    5. **Post the error message**

       | Field       | Value                                        |
       | ----------- | -------------------------------------------- |
       | **Label**   | `ERR`                                        |
       | **Method**  | `Page-Set-Messages`                          |
       | **Message** | `@unescapeHTML(@getWorstMessageName(tools))` |

       For more information, see [unescapeHTML](/flexi-capture/connectors/pega/pega-func-other#unescapehtml).

       Add the following **Jump** condition:

       | When   | if true       | true param | if false | false param |
       | ------ | ------------- | ---------- | -------- | ----------- |
       | `true` | Exit Activity |            |          |             |

           <Frame>
             <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega116.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=8225fc634ae551bd51dbbc6c1aeadbaf" alt="Screenshot of substep 5 in Pega labeled ERR, using the Page-Set-Messages method with the Message set to @unescapeHTML(@getWorstMessageName(tools))." width="1092" height="241" data-path="images/flexi-capture/connectors/Pega116.png" />
           </Frame>

           <Frame>
             <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega117.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=e61995d460bec6a0e6c570aac6e98328" alt="Screenshot of the Jump conditions for substep 5 in Pega, with a When value of true that exits the activity." width="931" height="256" data-path="images/flexi-capture/connectors/Pega117.png" />
           </Frame>

    6. **Increment the attachment counter**

       Set **Label** to `INC`, set **Method** to `Property-Set`, and set the property as follows:

       | PropertiesName | PropertiesValue   |
       | -------------- | ----------------- |
       | `Local.Index`  | `Local.Index + 1` |

           <Frame>
             <img src="https://mintcdn.com/abbyy/KEmWsO92hkr7eybZ/images/flexi-capture/connectors/Pega118.png?fit=max&auto=format&n=KEmWsO92hkr7eybZ&q=85&s=c00c72678eb35dc51d238503bb1c37ac" alt="Screenshot of substep 6 in Pega labeled INC, using the Property-Set method with a PropertiesName of Local.Index and a PropertiesValue that increments Local.Index by one." width="1078" height="199" data-path="images/flexi-capture/connectors/Pega118.png" />
           </Frame>
  </Step>
</Steps>
