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) »
  • Custom Field Hook
Pages: [1]

Author Topic: Custom Field Hook  (Read 1009 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
Custom Field Hook
February 05, 2012, 12:48:07 pm
Having some issues with the custom field hook, specifically with the $params that are passed.

If I update a custom value using the API, such as:

Code: [Select]
$results=civicrm_api("Contact","update", $updateContact);
Then $params only returns those custom values that were changed by the API.

However, if I use the web interface, and look at a contact and choose to edit a set of custom fields, then the $params returns all of the custom values, even if only one of them was changed. This makes it impossible (as far as I can tell) to know which of the custom fields was changed.

I'm trying to run a function when one of those custom fields is changed (the function depends on which one is changed), and I can't see how to do that when a custom field is changed via the web interface. It works fine when changed using the API, but in our setup, both API changes and web interface changes are going to happen.

Any ideas on how I can get around this? Or if I am doing something wrong / misunderstanding something?

Brian

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Custom Field Hook
February 05, 2012, 01:04:41 pm
You can't use the api to determine which custom fields have changed unless you do a 'GET' first & compare.
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

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: Custom Field Hook
February 05, 2012, 02:52:52 pm
So I would have to do a GET in a pre hook first?

How do I get the value from there in the custom hook? Sorry if this is an obvious question, but something I just don't know how to do.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Custom Field Hook
February 05, 2012, 03:01:43 pm
Nope - not obvious. I think you need to cache it in your session or a static variable.
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

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: Custom Field Hook
February 05, 2012, 04:59:17 pm
Thanks Eileen. I think I have figured out how to store and retrieve session variables. The problem I am having is where I can do the 'GET' in the first place.

The _pre hook isn't called on Custom Field changes, and the _custom hook is a post hook so calling the _GET there would give the me the already changed value. So where would I put the 'GET' api call in order to the get the custom field value of the contact being changed before it is changed?

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: Custom Field Hook
February 12, 2012, 08:31:49 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) »
  • Custom Field Hook

This forum was archived on 2017-11-26.