# How To: Combine Documents

Use this guide to combine documents you previously generated through the S-Docs package.

{% hint style="info" %}
Before you start:

* Confirm your S-Doc generation process: **SDK or LWC**
* Use a supported format: **PDF**, **PDF-Upload**
* Activate and test the Flow in Salesforce
* Make sure the target users can access the Flow, base record, and related S-Doc records
  {% endhint %}

<figure><img src="/files/KoiUauhVyzPCt5fZyeAX" alt="Flow Snippet for Combining S-Docs" width="339"><figcaption></figcaption></figure>

### Build the Flow

{% stepper %}
{% step %}

#### Gather Records

Use **Get Records** to return the **S-Doc** records that match your entry criteria.

* Sort the results in **your preferred order**
* Choose **Store all records**
  {% endstep %}

{% step %}

#### Loop the Data & Assign to Collection Variable

Loop through the collected S-Doc records, assigning each **Record ID** to a Collection Variable with **Data Type Text.**
{% endstep %}

{% step %}

#### Configure the Combine Documents Action

Add your Collection Variable of S-Doc IDs

<p align="center"><img src="/files/xXoeCZGaaeXr3I6pFRVO" alt="Combine Document Flow Action" data-size="original"></p>

**Optional**

Include a prepared Collection Variable of record IDs to link the combined File to desired records or Libraries

* Without a specified location, find your combined document in the Files tab

Specify a Name for the combined File

* Default is "Combined Document"
  {% endstep %}

{% step %}

### Test Your Flow

Run the Flow and check:

* Files tab
* Files related list on specified record(s)
* Specified Libraries on Files tab
  {% endstep %}
  {% endstepper %}

### Related setup

Use these pages if you still need to configure the supporting pieces:

* LWC for Document Generation
* Generate Document Flow Action
* Generate with Input Flow Action


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/sdocs/automation-and-document-lifecycle/automate-with-flow/how-to-combine-documents.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
