Answers.Body: <p>In general, Matrix fields support delta saves, so you can mix existing blocks with new blocks when saving matrix fields. This is <a href="https://craftcms.com/docs/3.x/matrix-fields.html#saving-matrix-fields" rel="nofollow noreferrer">documented here</a>. Retaining existing blocks involves passing a <code>sortOrder</code> to the field which includes the IDs of all existing blocks you want to keep as well as an identifier for the newly created blocks.</p>
  <p>Adding new blocks programmatically can look something like this:</p>
  <pre class="lang-php prettyprint-override"><code>$existingMatrixBlocks = $entry-&gt;getFieldValue('my_matrix_field')-&gt;ids();
  $newMatrixBlocks = [
      'new:1' =&gt; ['type' =&gt; 'copy', 'fields' =&gt; ['text' =&gt; 'Lorem Ipsum']],
      'new:2' =&gt; ['type' =&gt; 'copy', 'fields' =&gt; ['text' =&gt; 'Dolor Sit']],
  ];
  $newSortOrder = array_merge($existingMatrixBlocks, array_keys($newMatrixBlocks));
  
  $entry-&gt;setFieldValue('my_matrix_field', [
      'sortOrder' =&gt; $newSortOrder,
      'blocks' =&gt; $newMatrixBlocks,
  ]);
  </code></pre>
  <p>However, I don't think you can do this using Feed Me's interface alone. You might be able to use <a href="https://docs.craftcms.com/feed-me/v4/developers/events.html" rel="nofollow noreferrer">Event Hooks</a> though to modify the data to be saved accordingly. Or build a custom importer that does the same thing.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-10T08:03:31.297Z
Answers.LastActivityDate: 2021-09-10T08:03:31.297Z
Answers.UserDisplayName: MoritzLost
Answers.Body: <p>As far as I know, this is not possible at the moment. You would need to build a custom importer and <em>re-post</em> existing block IDs as part of the <code>sortOrder</code> array.</p>
  <p><a href="https://craftcms.com/docs/3.x/matrix-fields.html#saving-matrix-fields" rel="nofollow noreferrer">See more in the documentation</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-10T07:59:57.590Z
Answers.LastActivityDate: 2021-09-10T07:59:57.590Z
Answers.UserDisplayName: Oli
Body: <p>Is it possible to add blocks to a Matrix field in an Entry using <strong>Feed Me</strong> without overwriting existing blocks? I know how to add multiple blocks at once with a single JSON file, but I won't have things in one file and they will need to be updated over time, and grouping them into one file isn't practical in this instance.</p>
  <p>In other words, if I have a Matrix field block called Awards, and entries will accumulate multiple Awards over time, each time Adding a new Awards block without removing the older Award blocks. Currently when I try this in Feed Me it just wipes the field clean and adds the new one and deleting any previous entries.</p>
  
Tags: <matrix><plugin-feedme>
Title: Cumulative Addition of Matrix field elements with Feed Me
ThreadText: # Cumulative Addition of Matrix field elements with Feed Me
  
  (Asked by: username_0 on 2021-09-09)
  
  Is it possible to add blocks to a Matrix field in an Entry using **Feed Me** without overwriting existing blocks? I know how to add multiple blocks at once with a single JSON file, but I won't have things in one file and they will need to be updated over time, and grouping them into one file isn't practical in this instance.
  
  In other words, if I have a Matrix field block called Awards, and entries will accumulate multiple Awards over time, each time Adding a new Awards block without removing the older Award blocks. Currently when I try this in Feed Me it just wipes the field clean and adds the new one and deleting any previous entries.
  
  **Tags:** matrix, plugin-feedme
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-09-10. Score: 2 | Accepted answer
  
  In general, Matrix fields support delta saves, so you can mix existing blocks with new blocks when saving matrix fields. This is [documented here](https://craftcms.com/docs/3.x/matrix-fields.html#saving-matrix-fields). Retaining existing blocks involves passing a `sortOrder` to the field which includes the IDs of all existing blocks you want to keep as well as an identifier for the newly created blocks.
  
  Adding new blocks programmatically can look something like this:
  
  ```php
  $existingMatrixBlocks = $entry->getFieldValue('my_matrix_field')->ids();
  $newMatrixBlocks = [
      'new:1' => ['type' => 'copy', 'fields' => ['text' => 'Lorem Ipsum']],
      'new:2' => ['type' => 'copy', 'fields' => ['text' => 'Dolor Sit']],
  ];
  $newSortOrder = array_merge($existingMatrixBlocks, array_keys($newMatrixBlocks));
  
  $entry->setFieldValue('my_matrix_field', [
      'sortOrder' => $newSortOrder,
      'blocks' => $newMatrixBlocks,
  ]);
  
  ```
  
  However, I don't think you can do this using Feed Me's interface alone. You might be able to use [Event Hooks](https://docs.craftcms.com/feed-me/v4/developers/events.html) though to modify the data to be saved accordingly. Or build a custom importer that does the same thing.
  
  
  ---
  
  ### Answer by username_2 on 2021-09-10. Score: 2
  
  As far as I know, this is not possible at the moment. You would need to build a custom importer and *re-post* existing block IDs as part of the `sortOrder` array.
  
  [See more in the documentation](https://craftcms.com/docs/3.x/matrix-fields.html#saving-matrix-fields).
  
  
  ---
  
  