CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Email on change of custom field
Pages: [1]

Author Topic: Email on change of custom field  (Read 1119 times)

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Email on change of custom field
August 14, 2011, 04:05:40 pm
I'm trying to use the hooks to send an e-mail when a specific custom field is changed.

The civicrm_pre hook though doesn't seem to be triggered by edits to custom fields.

The civicrm_custom hook is called after the changes have been written to the database, so I'm unable to tell which custom fields within a custom group were actually changed (the e-mail will go to a different person depending on which custom field has been changed).

I suppose I could have more custom groups with only one custom field in them, that way when a custom group was edited, I would know for sure which custom field was changed with civicrm_custom hook, but I'd prefer it if I didn't have to do that.

Any ideas?

Brian

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Email on change of custom field
August 14, 2011, 10:26:28 pm
Hi,

I had the impression (likely incorrect) that only the fields that were changed got passed into the civicrm_custom hook. I agree a pre hook would be useful
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

e_mason

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 1
  • Eliot Mason
  • CiviCRM version: 4.05
  • CMS version: Drupal 7
  • MySQL version: 5.1xx
  • PHP version: 3.53
Re: Email on change of custom field
August 15, 2011, 06:20:27 am
any chance you could use a profile field set to auto-notify?

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Email on change of custom field
August 15, 2011, 07:48:54 am
Quote
I had the impression (likely incorrect) that only the fields that were changed got passed into the civicrm_custom hook

That is what I hoped would happen when I changed a field, but instead it returned the value of every field in the group regardless of whether it had changed - and no flag to indicate which ones had been changed.

As you say a custom-pre hook would be useful. How do we go about doing that?

Quote
any chance you could use a profile field set to auto-notify

I could but I actually want to do more than just notify - I just simplified it for the forum post. A pre hook is really the way I want to go - although as I mentioned in OP, I can temporarily get around it by having only one custom field per custom group.

Thanks again.

Brian

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Email on change of custom field
February 12, 2012, 08:32:57 am
I found a way around this. I'm not a programmer, so it is a bit of a hack job, but if anyone is interested it allows you to see the previous values of all fields inside the custom group that has been changed inside of the hook_civicrm_custom.

http://issues.civicrm.org/jira/browse/CRM-9649

It would be great if this was tidied up and found its way into core.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Email on change of custom field

This forum was archived on 2017-11-26.