API Bulk upload and logic hooks

Dear all,

I built a custom Module which should represent better our company structure in CRM. The repository of these data are in an external database. Out from there I built an API interface witch brings the data to CRM. I have experience on this, because we us this for other occasions as well. As I don't know the relation of each record at the moment of the selection in the external database, I decided to relate the records witch resides in CRM at the moment of the import with a logic hook.

This works very well for single POST calls. Because of the data amount I would like to import the data with bulk-calls. Also this works fine until the logic hook should do his job. In that case the hook triggers only once.

Does anybody out there know something about this issue? I tried before_ and after_save hooks. We're on SUGAR 11

This is how my hook looks like

class pskHook {
    
    // before Save Hooks
    public function getAccount ($bean, $event, $arguments) {
        
        $psk = $bean->mg_psk_no_c;
        
        $accounts = BeanFactory::newBean('Accounts');

        $query = new SugarQuery();
        $query->select(array('id', 'mg_psk_c'));
        $query->from($accounts, array('team_security' => true));
        $query->where()->equals('mg_psk_c', $psk);
        $account_list = $query->execute();
                
        if ( $account_list != null ) {
            $rel_name = 'psk_accounts_1';
            if($bean->load_relationship($rel_name)){
                foreach ($account_list as $acct) {
                     $bean->$rel_name->add($acct['id']);
                }
            }
        } 
    }
}

Any inputs are really appreciated. Thank you very much to share your thoughts.

Rene

Parents
  • Hi Rene, 

    Just to confirm if I understand the scenario correctly: 

    - You are doing a bulk POST request to your instance to create records

    - There is an before_save logic hook for the module calling pskHook()

    Expected: The logic hook fires for all records

    Actual: The logic hook only fires for the first

    --

    I think we need more logging to understand better what data is processed. Can you add _ppl() to your logic hook to confirm when the hook is called and two more _ppl() into the two IF statements to make sure those are true for all records? Afterwards check sugarcrm.log to confirm that what you see in the logs. 

    Also is it possible to convert the before_save to an after_save logic hook to see if that makes any difference? 

  • Hello Denis,

    Thank you very much for your answer. I'm in a bit of a hurry at the moment, but you've made me take another look at the whole thing with your answer. And it looks good. I will get back to you here.

    Thank you very much again.
    Rene

Reply Children
No Data