Create a call with reminder to invitees

Hello all

I am trying to create a new Call via custom code. This is the code:

 $callAux = new Call();
        $callAux->assigned_user_id=$userId;
        $accountAux = new Account();
        $accountAux->retrieve($accountId);
        $callAux->name = "Name";
        $callAux->direction='order';
        $hoy = date("Y-m-d H:i:s");
        $callAux->description="description";
        $fecha_start = $NewDate=Date('Y-m-d 17:00:00', strtotime("+3 days"));
        $fecha_end = $NewDate=Date('Y-m-d 17:15:00', strtotime("+3 days"));

        // Comprobamos que la fecha no sea un fin de semana
       if(date('w', strtotime($fecha_start)) == 6)
        {
           $fecha_start = $NewDate=Date($fecha_start, strtotime("+2 days"));
        $fecha_end = $NewDate=Date($fecha_end, strtotime("+2 days"));
        }
        else if( date('w', strtotime($fecha_start)) == 0) {
                $fecha_start = $NewDate=Date($fecha_start, strtotime("+1 days"));
                $fecha_end = $NewDate=Date($fecha_end, strtotime("+1 days"));
        }
        
        $callAux->date_start =$fecha_start;
        $callAux->date_end=$fecha_end;
        $callAux->duration_minutes=15;
        $callAux->duration_hours=0;
        $callAux->status='Planned';

//SET UP REMINDERS

        $callAux->reminder_time=1;
        $callAux->email_reminder_time=1;

        $callAux->parent_type='Accounts';
        $callAux->parent_id=$accountId;
        $callAux->product_related_c="pd2";
        $callAux->proyecto_c='P1';
        $callAux->save();

        $callAux->load_relationship('accounts');
        $callAux->accounts->add($accountId);

However this creates the call, but inside I get thounsands of reminders set up. In the db for this call created I get 2047 records in the reminders and reminders_invitees table.

How do I must create the call so the call only assigns a pop-up window reminder to the assigned user?

Thanks a lot!

I would check for some unintended recursion in that code…

Where are you calling it from?

If it’s being called from a logic_hook, check that it is not reentering when you run one of those “save” commands. This would explain that it creates “infinite” reminders until it runs out of resources (timeout, or out of memory) and leaves a FATAL error in your logs (always check both your logs!)

Hello

Yes it is being called from a Logic_Hook before safe in Meetings module when the meeting record is saved as Held. However what you say would make more sense for me if instead creating the reminder for the call, the loop would create also several calls with one reminder per call.

The code creates a new Call record, so the loop would have to create several Calls with one reminder. Dont you think?. I have checked the logs and forced a “text” to be written every time the function is calld, and it is being shown only once when the meeting is saved as “Held”. nothing else is shown in the log files

Any ideas or suggestions?

Thanks a lot for your help!!!

The loop could be in a different part of your system. It could involve a Workflow that gets triggered by your code and does something else. Or you could have more than one logic hook getting run on this event, or in any subsequent events that it triggers.

Any way, if you look at your logs and see it going in a loop, you should be able to find out. Adding 2000 records takes a long time to run, you can see it happening and eventually you will know what part of the code is going in loops.

It could be logic_hook re-entry, but also a 2-way relationship that is being traversed in loop (going from record A to B, then from B to A, then repeating that forever). Or it could be some 3-way arrangement of any of these things.

Also if you are running out of resources eventually, as my theory goes, you will see that error as a FATAL in you php_errors.log