How to only fire logic hook on main record?

Hi everyone.

Hopefully something fairly easy. I've built a logic hook for opportunities which utilizes the "Before_Save" format. However the customer has had past code that fires Opportunity logic hooks whenever the account is saved. I cannot find a way to only fire my logic hook when the record in opportunities is saved only.

So basically if they are importing records it ignores this, also if they are saving on Accounts this logic hook would not fire. So only when the Opportunity record itself is saved. I don't seem to have arguments['module'] on the before save.

Any ideas?

Thanks!

  • Daniel, what exactly your hook does? Does this hook do calculation based on specific modifield fields on Opportunity? You can evaluate the attribute $bean->fetched_rows in order to compare old db fields against new bean fields, so you can decide whether to execute it or not.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi Andre.

    I am checking if there are any contacts on an opportunity, and if there are then stop the save. However I don't want this check happening if the user saves an Account. It's firing on any related Opportunities currently.

    Thanks!

  • Hi Daniel,

    Can you please go through this link once and check if it helps for you?

  • This is a tricky one. We had a similar issue, and we took an easy approach but not really a "neat" solution: If you just want to add this validation for Opportunity API calls, you can look at the Request URL : 

    $_REQUEST['__sugar_url']

    and check if it was triggered for Opportunities or Not.

    If it was triggered on Account Save, there would be no "Opportunities" in the URL. Shrug