Answers.Body: <p><code>isValid</code> should be set on the <code>$event</code> variable, not on <code>$event-&gt;element</code>:</p>
  <pre><code>Event::on(Process::class, Process::EVENT_STEP_BEFORE_ELEMENT_SAVE, function (FeedProcessEvent $event) {
      $myField=$event-&gt;feedData['myfieldname'];
      if ($myField == null){
          $event-&gt;isValid=false;
      }
  });
  </code></pre>
  <p>I haven't tested but looking at the <a href="https://github.com/craftcms/feed-me/blob/develop/src/services/Process.php#L420" rel="nofollow noreferrer">feed-me source code</a>, this should work.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-26T15:10:43.070Z
Answers.Text: Thanks for the answer. I got it working, but I'm looking to access the field's in FeedMe. I have a field in FeedMe called "Merchants" but some of imported entries won't get matched up to anything, so I'm trying to stop them being saved if they don't match up.
Answers.UserDisplayName: JMKelley
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-26T15:17:25.207Z
Answers.Text: Updated the question above.
Answers.UserDisplayName: JMKelley
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-25T16:51:11.917Z
Answers.LastActivityDate: 2020-11-25T16:51:11.917Z
Answers.UserDisplayName: nstCactus
Answers.Body: <p><strong>Updated</strong></p>
  <p>After a lot of tinkering - I finally found out how to check if the field is matching/existing and if nothing matches - Skip adding this element.</p>
  <pre><code>Event::on(
  Process::class, 
  Process::EVENT_STEP_BEFORE_ELEMENT_SAVE, 
  function (craft\feedme\events\FeedProcessEvent $event) {
    switch($event-&gt;feed['name']){
      case 'offers':
  
        $merchants = $event-&gt;element-&gt;merchants;
        if (sizeof($merchants) === 0) {
            $event-&gt;isValid=false;
        }
      break;
    }
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-30T16:40:06.227Z
Answers.Text: Looks like the only thing that differs from nstCactus' answer is your additional check code?  IMO that doesn't really improve the answer as the key is in the ``$event->isValid`` line which was pointed out in that answer. (You also didn't mention in the question that ``$merchants`` is supposed to be an array?)
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-30T18:42:16.420Z
Answers.Text: Sure, I've reimbursed the internet points.
Answers.UserDisplayName: JMKelley
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-27T12:56:56.103Z
Answers.LastActivityDate: 2020-11-27T12:56:56.103Z
Answers.UserDisplayName: JMKelley
Body: <p>Is there a way on Feedme to not import an entry if it doesn't have a match on a specific field?</p>
  <blockquote>
  <p>e.g. If there is no entry that it matches up to, don't import it.</p>
  </blockquote>
  <p>Here's the current code I have:</p>
  <pre><code>Event::on(Process::class, Process::EVENT_STEP_BEFORE_ELEMENT_SAVE, function (FeedProcessEvent $event) {
      $myField=$event-&gt;feedData['myfieldname'];
      if ($myField == null){
          $event-&gt;element-&gt;isValid=false;
      }
  });
  </code></pre>
  <p>The above processes the data getting loaded in. Here's code for processing data after it's parsed.</p>
  <pre><code>Event::on(Fields::class, Fields::EVENT_AFTER_PARSE_FIELD, function(FieldEvent $event) {
      if ($event-&gt;fieldHandle['merchants'] == null) {
      $event-&gt;isValid=false;
      }
  });
  </code></pre>
  
Tags: <plugin-development><plugin-feedme>
Title: Feedme Skip Entry if No Matching Elements on Field
ThreadText: # Feedme Skip Entry if No Matching Elements on Field
  
  (Asked by: username_0 on 2020-11-22)
  
  Is there a way on Feedme to not import an entry if it doesn't have a match on a specific field?
  
  > e.g. If there is no entry that it matches up to, don't import it.
  
  Here's the current code I have:
  
  ```
  Event::on(Process::class, Process::EVENT_STEP_BEFORE_ELEMENT_SAVE, function (FeedProcessEvent $event) {
      $myField=$event->feedData['myfieldname'];
      if ($myField == null){
          $event->element->isValid=false;
      }
  });
  
  ```
  
  The above processes the data getting loaded in. Here's code for processing data after it's parsed.
  
  ```
  Event::on(Fields::class, Fields::EVENT_AFTER_PARSE_FIELD, function(FieldEvent $event) {
      if ($event->fieldHandle['merchants'] == null) {
      $event->isValid=false;
      }
  });
  
  ```
  
  **Tags:** plugin-development, plugin-feedme
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-11-25. Score: 2 | Accepted answer
  
  `isValid` should be set on the `$event` variable, not on `$event->element`:
  
  ```
  Event::on(Process::class, Process::EVENT_STEP_BEFORE_ELEMENT_SAVE, function (FeedProcessEvent $event) {
      $myField=$event->feedData['myfieldname'];
      if ($myField == null){
          $event->isValid=false;
      }
  });
  
  ```
  
  I haven't tested but looking at the [feed-me source code](https://github.com/craftcms/feed-me/blob/develop/src/services/Process.php#L420), this should work.
  
  > **Comments:**
  > **username_0**: Thanks for the answer. I got it working, but I'm looking to access the field's in FeedMe. I have a field in FeedMe called "Merchants" but some of imported entries won't get matched up to anything, so I'm trying to stop them being saved if they don't match up.  
  > **username_0**: Updated the question above.  
  
  ---
  
  ### Answer by username_0 on 2020-11-27. Score: 0
  
  **Updated**
  
  After a lot of tinkering - I finally found out how to check if the field is matching/existing and if nothing matches - Skip adding this element.
  
  ```
  Event::on(
  Process::class, 
  Process::EVENT_STEP_BEFORE_ELEMENT_SAVE, 
  function (craft\feedme\events\FeedProcessEvent $event) {
    switch($event->feed['name']){
      case 'offers':
  
        $merchants = $event->element->merchants;
        if (sizeof($merchants) === 0) {
            $event->isValid=false;
        }
      break;
    }
  });
  
  ```
  
  > **Comments:**
  > **username_2**: Looks like the only thing that differs from username_1' answer is your additional check code?  IMO that doesn't really improve the answer as the key is in the ``$event->isValid`` line which was pointed out in that answer. (You also didn't mention in the question that ``$merchants`` is supposed to be an array?)  
  > **username_0**: Sure, I've reimbursed the internet points.  
  
  ---
  
  