Answers.Body: <p>Not as far as I know. You could, however, apply <a href="https://github.com/civicrm/civicrm-core/pull/16714" rel="nofollow noreferrer">this patch</a>, which introduces generic <code>preInsert</code> and <code>preUpdate</code> hooks to CiviCRM. The copy and demo code for PR explains how you can use these hooks.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-17T05:22:05.810Z
Answers.Text: Thanks for the suggestion. I implemented that patch and tested it. Unfortunately, custom data doesn't flow through the DAO layer. The update is handled with a straight sql call in the BAO layer: https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/BAO/CustomValueTable.php#L255
Answers.UserDisplayName: lcdservices
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-16T12:27:27.133Z
Answers.LastActivityDate: 2020-04-16T12:27:27.133Z
Answers.UserDisplayName: Christian Wach
Body: <p>I feel like I've hit this issue before and found a solution, but I'm drawing a blank right now. I need to be able to compare the value of a custom data field before it's saved in order to conditionally perform another action. For core fields I would typically do this with the pre hook -- as you can look up the existing value and compare with the value passed in the hook. But the pre hook is not hit with custom value updates (why?), and the custom hook is hit <em>after</em> the data is saved, so you can't compare with the prior value (it's basically the equivalent of the post hook, specific to custom data).</p>
  
  <p>I'd rather not work with form hooks, as I want this to be universally triggered without me needing to track down all the forms where the data might be potentially updated.</p>
  
  <p>Any suggestions?</p>
  
Tags: <custom-fields><hooks>
Title: Is there a hook to impact custom data before it's saved?
ThreadText: # Is there a hook to impact custom data before it's saved?
  
  (Asked by: username_0 on 2020-04-15)
  
  I feel like I've hit this issue before and found a solution, but I'm drawing a blank right now. I need to be able to compare the value of a custom data field before it's saved in order to conditionally perform another action. For core fields I would typically do this with the pre hook -- as you can look up the existing value and compare with the value passed in the hook. But the pre hook is not hit with custom value updates (why?), and the custom hook is hit *after* the data is saved, so you can't compare with the prior value (it's basically the equivalent of the post hook, specific to custom data).
  
  I'd rather not work with form hooks, as I want this to be universally triggered without me needing to track down all the forms where the data might be potentially updated.
  
  Any suggestions?
  
  **Tags:** custom-fields, hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-04-16. Score: 3
  
  Not as far as I know. You could, however, apply [this patch](https://github.com/civicrm/civicrm-core/pull/16714), which introduces generic `preInsert` and `preUpdate` hooks to CiviCRM. The copy and demo code for PR explains how you can use these hooks.
  
  > **Comments:**
  > **username_0**: Thanks for the suggestion. I implemented that patch and tested it. Unfortunately, custom data doesn't flow through the DAO layer. The update is handled with a straight sql call in the BAO layer: https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/BAO/CustomValueTable.php#L255  
  
  ---
  
  