# Creating & Deleting Object Record Attachments Using Vault Loader

[Vault Loader](/en/lr/26597/) allows you to bulk create or delete object record attachments in your Vault if attachments are enabled for that object type. When creating attachments, if the attachment already exists, Vault uploads the attachment as a new [version](/en/lr/24287/#attachment_versioning) of the existing attachment. Learn more about [Configuring Attachments](/en/lr/58626/).

## How to Load Object Record Attachments

Before loading object record attachments:

  * [Upload files to file staging](/en/lr/26597/#ftp) 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 object record attachment field values.

To load object record 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 the object type of the records on which to add or delete attachments.
  4. In the **Action Type** picklist, select **Create Attachments** or **Delete Attachments**.
  5. Optional: If deleting attachments using a CSV file that identifies attachments by an external id, in the **Key Field** drop-down, select **External ID**.
  6. Optional: Click **Map Fields** to access the field [mapping][6] grid.
  7. Click **Start Load**.

## Field Mapping {#mapping}

With field mapping, you can choose to map specific object fields to the columns in your CSV input file. For example, if your CSV contains a _VeePharm ID_ column with the external ID values for each object record 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 object record 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 the object of the records to which to add the attachments from the **Object** drop-down list.
  2. In the **Action Type** drop-down, select **Create Attachments** or **Delete Attachments**.
  3. Click the **Map Fields** button to access the field mapping grid. You can also load previously saved mappings by clicking the **Map Fields** drop-down button and selecting **Load Saved Mapping**.
  4. Optional: Apply any additional column filters.
  5. Optional: Click **Clear Fields** to clear all existing column mappings.
  6. Optional: Use the **Search** box to search for a specific object column.
  7. In the **CSV Column**, select a column name from the applicable drop-down list to map to the desired object 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.
  8. Optional: Click **Save Mapping** to save your current column mappings.
  9. 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 object record attachments using Vault Loader.

#### Create Attachments

<table class="wbord">
  <tr>
    <td>
      <p>
        <strong>Column Header</strong>
      </p>
    </td>
    <td>
      <p>
        <strong>Field</strong>
      </p>
    </td>
    <td>
      <p>
        <strong>Example Value</strong>
      </p>
    </td>
    <td>
      <p>
        <strong>Description</strong>
      </p>
    </td>
  </tr>
  <tr>
    <td>
      <p>
        id
      </p>
    </td>
    <td>
      <p>
        ID
      </p>
    </td>
    <td>
      <p>
        V5A000000001002
      </p>
    </td>
    <td>
      <p>
        The object record ID to which Vault Loader should add the attachment.
      </p>
    </td>
  </tr>
  <tr>
    <td>
      <p>
        filename__v
      </p>
    </td>
    <td>
      <p>
        File Name
      </p>
    </td>
    <td>
      <p>
        NyaxaPrescribingInformation.docx
      </p>
    </td>
    <td>
      <p>
        The filename of the source file for the attachment.
      </p>
    </td>
  </tr>
  <tr>
    <td>
      <p>
        file
      </p>
    </td>
    <td>
      <p>
        File
      </p>
    </td>
    <td>
      <p>
        u275657/NyaxaPrescribingInformation.docx
      </p>
    </td>
    <td>
      <p>
        The filepath of the attachment on file staging.
      </p>
    </td>
  </tr>
  <tr>
    <td>
      <p>
        description__v
      </p>
    </td>
    <td>
      <p>
        Description
      </p>
    </td>
    <td>
      <p>
        Informative pamphlet for prescribers
      </p>
    </td>
    <td>
      <p>
        Optional: A description of the attachment. Maximum 100 characters.
      </p>
    </td>
  </tr>
  <tr>
    <td>
      <p>
        external_id__v
      </p>
    </td>
    <td>
      <p>
        External ID
      </p>
    </td>
    <td>
      <p>
        NXA-2020123
      </p>
    </td>
    <td>
      <p>
        Optional: Set an external ID value on the attachment.
      </p>
    </td>
  </tr>
</table>

#### Delete Attachments

<table class="wbord">
  <tr>
    <td>
      <p>
        <strong>Column Header</strong>
      </p>
    </td>
    <td>
      <p>
        <strong>Field</strong>
      </p>
    </td>
    <td>
      <p>
        <strong>Example Value</strong>
      </p>
    </td>
    <td>
      <p>
        <strong>Description</strong>
      </p>
    </td>
  </tr>
  <tr>
    <td>
      <p>
        id
      </p>
    </td>
    <td>
      <p>
        ID
      </p>
    </td>
    <td>
      <p>
        V5A000000001002
      </p>
    </td>
    <td>
      <p>
        The object record ID from which Vault Loader should remove the attachment.
      </p>
    </td>
  </tr>
  <tr>
    <td>
      <p>
        attachment_id
      </p>
    </td>
    <td>
      <p>
        Attachment ID
      </p>
    </td>
    <td>
      5
    </td>
    <td>
      The ID of the attachment to remove. If you are identifying attachments by external_id, do not include this column.
    </td>
  </tr>
  <tr>
    <td>
      <p>
        external_id__v
      </p>
    </td>
    <td>
      <p>
        External ID
      </p>
    </td>
    <td>
      <p>
        NXA-2020123
      </p>
    </td>
    <td>
      <p>
        Optional: Identify attachments by an external id value rather than attachment_id.
      </p>
    </td>
  </tr>
</table>

## Example Input for Creating Object Record Attachments

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

## File Validation

Before beginning the Vault Loader job to create object record 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 attachments you're loading.

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 [Vault Loader permissions](/en/lr/26597/#about-vault-loader-permissions), your security profile must include the _Edit_ permission on the object type to which you are adding attachments.

Additionally, your security profile must include the _Attachments: Upload: Execute_ permission and, if including the _Description_ field, the _Attachments: Edit Descriptions: Execute_ permission, to load attachments for any object with _Use Action Security to control attachments_ enabled. Learn more about [securing object attachments](/en/lr/58626/#secure).

 [6]: #mapping
