# Creating & Deleting Document Attachments Using Vault Loader

<a href="/en/gr/26597/">Vault Loader</a>
 allows you to bulk create and delete document attachments in your Vault. This works for version-specific attachments and attachments at the document level. If the attachment already exists, Vault uploads the attachment as a new version of the existing attachment. Learn more about <a href="/en/gr/24287/#version-specific">attachment versioning</a>
.

## How to Load Document Attachments

Before loading document attachments:

  * <a href="/en/gr/26597/#ftp">Upload files to file staging</a>
 or the <a class="external-link " href="https://developer.veevavault.com/api/" target="_blank" rel="noopener">Vault APIs<i class="fa fa-external-link" aria-hidden="true"></i></a> Create a Folder or File (Files under 50MB) or Resumable Upload Session (files over 50MB) endpoints.
  * Prepare the CSV input file containing document attachment field values.

To load document attachments:

  1. In the left panel of the **Loader** tab, click **Load**.
  2. For the **CSV File**, click **Choose** and select the CSV input file.
  3. In the **Entity Type** picklist, select **Document Attachments**.
  4. In the **Action Type** picklist, select **Create** or **Delete**.
  5. In the **Key Field** drop-down, select the **ID** field. This option is only required for the _Delete_ action.
  6. Optional: Click **Map Fields** to access the field mapping grid.
  7. Click **Start Load**.

Before processing the request, Vault [validates the selected CSV file][5]. If the file is valid, Vault begins processing the request. When finished, you'll receive a <a href="/en/gr/26597/#loader-notifications-outputs">Vault notification and email</a>
 with request details and CSV output files.

## Field Mapping

With field mapping, you can choose to map specific document fields to the columns in your CSV input file. For example, if your CSV contains a _VeePharm ID_ column containing external id numbers for each document attachment source file, you can map the _external\_id\_\_v_ field to the _VeePharm ID_ column to populate the _external\_id\_\_v_ field on the document attachment with the value in the _VeePharm ID_ column. If you skip this step, Vault applies auto mapping to all columns in your CSV.

To map fields:

  1. After selecting your CSV file, select **Document Attachments** from the **Object** drop-down list.
  2. In the **Action Type** drop-down, select **Create** or **Delete**.
  3. In the **Key Field** drop-down, select **ID**. Note that this option is only required for the _Delete_ action.
  4. Click the **Map Fields** button to access the field mapping grid. You can also load previously saved mapping by clicking the **Map Fields** drop-down button and selecting **Load Saved Mapping**.
  5. Optional: Apply any additional column filters.
  6. Optional: Click **Clear Fields** to clear all existing column mappings.
  7. Optional: Use the **Search** box to search for a specific object column.
  8. In the **CSV Column**, select a column name from the applicable drop-down list to map to the desired field or label. You can enter a page number above the field mapping grid to jump to a specific page, or use the navigation arrows.
  9. Optional: Click **Save Mapping** to save your current column mappings.
  10. When ready, click **Start Load**.

### Additional Details

  * Vault uses yellow highlighting for required CSV columns.
  * The drop-down lists in the CSV column displays _(no mapping)_ for available columns of the CSV.
  * Select _(no mapping)_ to un-map a previously mapped column.
  * Already mapped fields are unavailable in the CSV column drop-down until they are un-mapped.

## Preparing the CSV Input File {#prepare}

Prepare a CSV input file with the following values. You must use UTF-8 encoding in your CSV file to create or delete document attachments using Vault Loader.

To create document attachments:

<table class="wbord">
  <tr>
    <td>
      <strong>Column Header</strong>
    </td>
    <td>
      <strong>Field</strong>
    </td>
    <td>
      <strong>Example Value</strong>
    </td>
    <td>
      <strong>Description</strong>
    </td>
  </tr>
  <tr>
    <td>
      document_id__v
    </td>
    <td>
      Document id
    </td>
    <td>
      127
    </td>
    <td>
      The id of the document to which Vault Loader should add the attachment.
    </td>
  </tr>
  <tr>
    <td>
      filename__v
    </td>
    <td>
      File Name
    </td>
    <td>
      gludacta_brochure.docx
    </td>
    <td>
      The filename of the source file for the attachment.
    </td>
  </tr>
  <tr>
    <td>
      file
    </td>
    <td>
      File
    </td>
    <td>
      /u1400167/gludacta_2020/gludacta_brochure.docx
    </td>
    <td>
      The filepath of the attachment on file staging.
    </td>
  </tr>
  <tr>
    <td>
      description__v
    </td>
    <td>
      Description
    </td>
    <td>
      2020 Gludacta Patient Brochure
    </td>
    <td>
      Optional: A description of the attachment. Maximum value 100 characters.
    </td>
  </tr>
  <tr>
    <td>
      major_version_number__v
    </td>
    <td>
      Major Version Number
    </td>
    <td>
      1
    </td>
    <td>
      Optional: The major version of the source document.
    </td>
  </tr>
  <tr>
    <td>
      minor_version_number__v
    </td>
    <td>
      Minor version Number
    </td>
    <td>
      3
    </td>
    <td>
      Optional: The minor version of the source document.
    </td>
  </tr>
  <tr>
    <td>
      external_id__v
    </td>
    <td>
      External ID
    </td>
    <td>
      VEEV-12345
    </td>
    <td>
      Optional: Set an external ID value on the attachment.
    </td>
  </tr>
</table>

To delete document attachments:

<table class="wbord">
  <tr>
    <td>
      <strong>Column Header</strong>
    </td>
    <td>
      <strong>Field</strong>
    </td>
    <td>
      <strong>Example Value</strong>
    </td>
    <td>
      <strong>Description</strong>
    </td>
  </tr>
  <tr>
    <td>
      id
    </td>
    <td>
      ID
    </td>
    <td>
      566
    </td>
    <td>
      The id of the document attachment to delete.
    </td>
  </tr>
</table>

## Example Inputs for Creating and Deleting Document Attachments

  * Create Document Attachments. <a class="external-link " href="https://developer.veevavault.com/docs/sample-files/vault-create-document-attachments-sample-file.csv" target="_blank" rel="noopener">Download example input<i class="fa fa-external-link" aria-hidden="true"></i></a>.
  * Delete Document Attachments. <a class="external-link " href="https://developer.veevavault.com/docs/sample-files/vault-delete-document-attachments-sample-file.csv" target="_blank" rel="noopener">Download example input<i class="fa fa-external-link" aria-hidden="true"></i></a>.

## File Validation

Before beginning the Vault Loader job to create or delete document attachments, Vault checks that the selected CSV file meets certain criteria:

  * Is not empty
  * Does not contain empty columns
  * Includes a valid header row. Invalid header rows are those with no columns that match to metadata for the records you're loading.
  * If using the _Delete_ action, the column specified as the _Key Field_ must be mapped.

If your file is not valid, Vault displays a notification, stops the process, and allows you to select a new CSV file. If some of the header columns do not match metadata for your Vault, the notification will allow you to stop the load or ignore those columns and proceed.

## Related Permissions

In addition to the standard <a href="/en/gr/26597/#about-vault-loader-permissions">Vault Loader permissions</a>
, your security profile must include the _Application: All Documents: All Document Actions_ permission in order to create document attachments using Vault Loader.

 [5]: #prepare
