Process Definition not Triggered from $bean->save()

Hi everyone.

I am struggling to figure out why, but a process definition that uses the "Changes" method is not firing when a logic hook is using $bean->save(). The changes is a simple "No to Yes" but when saving the record it doesn't go into the processes.

I tried doing:


$dataChanges = $bean->dataChanges;
$bean->save();
$bean->dataChanges = $dataChanges;

But seemingly had no luck. Has anyone seen this before?

Thanks

Dan

  • Hi Daniel,

    You are using which version of SugarCRM?

    As from version 10.2 $bean->dataChanges is no longer supported. You need to use $bean->stateChanges instead.

    Hope it will work fine. Have a good day!

  • Hi Maryam. 

    I am on 10.0.3 but I did try $statechanges but same issue I'm afraid. Any other suggestions would be really appreciated! 

    Thank you,

  • You are using which logic hook?

    Also, are you trying to call some function in your logic hook, and it is not calling? Is it the real problem? 

  • Hi Maryam, I am using before and after save. The issue is when doing $bean->save() in after save it doesn't seem to fire the process.

    I can see $bean->dataChanges is seeing the change which is the odd part.

  • Also slight note on this, if i comment out $bean->save() the process works just fine... So something with save function is causing the issue. 

  • Actually, process definition fires the logic hook. So for this, you need to re-check the design of your process definition that your implemented criteria are matching to trigger the process or not. 

    I believe there is a problem in the design of your PD, or maybe the criteria are not matching that is why the process is not triggering. When it will trigger then it will call your logic hook. 

  • Hi Maryam. The process definition simply checks if a field has changed from "No" to "Yes". It's seemingly that the $bean->save() is affecting the firing of the workflow. I'm not entirely sure why at the moment. But will keep looking!

  • Are you calling the save function of the same bean?

    If yes then it is wrong. Because by this it will be stuck in infinite loop. 

  • I am however I am stopping the infinite loop using the sugar recommend approach, unless I am still not doing something right? :) 

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    function contactsAfterSave($bean, $event, $arguments)
    {
    $GLOBALS['log']->error('### contactsAfterSave Started');
    if (!isset($bean->ignore_update_c) || $bean->ignore_update_c === false)
    {
    $GLOBALS['log']->error('### contactsAfterSave Update');
    if ($bean->contact_type_c == 'Child')
    {
    $this->checkForACPFieldChanges($bean, $event, $arguments);
    }
    if ($bean->contact_type_c == 'Contact')
    {
    $this->checkForProfDetailsChanges($bean,$event,$arguments);
    }
    $bean->ignore_update_c = true;
    $dataChanges = $bean->dataChanges;
    $bean->save();
    $bean->dataChanges = $dataChanges;
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • We should never call $bean->save in any before_save,after_save logic hook of the same bean. Because before save will call the save and due to this again before save logic hook will call and it will so on. 

1 2