<p>Your script probably chokes because you're interacting with an undeclared variable <code>$params</code> – i.e. change</p>

<pre><code>if($params['isNewEntry']) {
</code></pre>

<p>to</p>

<pre><code>if($event-&gt;params['isNewEntry']) {
</code></pre>

CC BY-SA 3.0
2016-01-25T14:03:15.500Z
That seems to be working, but now now the following line is not working. $entry->authorId = $assignedCoach; while $entry->getContent()->coachId = $assignedCoach; is working fine.
David A McInnis
CC BY-SA 3.0
2016-01-25T14:25:04.367Z
Okay, I found the answer to the last question I had on this thread regarding authorId here > http://craftcms.stackexchange.com/questions/6722/use-onbeforesaveentry-event-to-update-entrymodel-properties
David A McInnis
CC BY-SA 3.0
2016-01-25T10:14:18.187Z
2016-01-25T10:14:18.187Z
Mats Mikkel Rummelhoff
<p>I am using the <a href="https://github.com/boboldehampsink/import" rel="nofollow">Import</a> plugin. This question doesn't have to do with the Import plugin which seems to be working swell, but instead with my <code>onBeforeSaveEntry</code> logic which seems to have botched the import process.</p>

<pre><code>public function init()
{
    parent::init();

    craft()-&gt;on('entries.onBeforeSaveEntry', function(Event $event)
    {

        if($params['isNewEntry']) {

            $entry = $event-&gt;params['entry'];

            $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
            $criteria-&gt;groupId = 1;
            $criteria-&gt;AffiliateId = $entry['AffiliateId']; 
            $criteria-&gt;limit = 1;
            $users = $criteria-&gt;find();

            if (!empty($users)) {           
                $assignedCoach = $users[0]-&gt;id;
                $entry-&gt;authorId = $assignedCoach;
                $entry-&gt;getContent()-&gt;coachId = $assignedCoach;
            }
        }        
    });

}
</code></pre>

<p>What am I doing wrong here? Also, any idea how I kill the import processes which seem to be hung at the moment?</p>

<entries><saveentry>
onBeforeSaveEntry is hanging on import
# onBeforeSaveEntry is hanging on import

(Asked by: username_0 on 2016-01-25)

I am using the Import plugin. This question doesn't have to do with the Import plugin which seems to be working swell, but instead with my onBeforeSaveEntry logic which seems to have botched the import process.
public function init()
{
    parent::init();

    craft()->on('entries.onBeforeSaveEntry', function(Event $event)
    {

        if($params['isNewEntry']) {

            $entry = $event->params['entry'];

            $criteria = craft()->elements->getCriteria(ElementType::User);
            $criteria->groupId = 1;
            $criteria->AffiliateId = $entry['AffiliateId']; 
            $criteria->limit = 1;
            $users = $criteria->find();

            if (!empty($users)) {           
                $assignedCoach = $users[0]->id;
                $entry->authorId = $assignedCoach;
                $entry->getContent()->coachId = $assignedCoach;
            }
        }        
    });

}

What am I doing wrong here? Also, any idea how I kill the import processes which seem to be hung at the moment?

**Tags:** entries, saveentry

---

## 1 answers

### Answer by username_1 on 2016-01-25. Score: 3 | Accepted answer

Your script probably chokes because you're interacting with an undeclared variable $params – i.e. change
if($params['isNewEntry']) {

to
if($event->params['isNewEntry']) {

> **Comments:**
> **username_0**: That seems to be working, but now now the following line is not working. $entry->authorId = $assignedCoach; while $entry->getContent()->coachId = $assignedCoach; is working fine.  
> **username_0**: Okay, I found the answer to the last question I had on this thread regarding authorId here > http://craftcms.stackexchange.com/questions/6722/use-onbeforesaveentry-event-to-update-entrymodel-properties  

---

