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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • CiviCRM query/function for 'first time' actions
Pages: [1]

Author Topic: CiviCRM query/function for 'first time' actions  (Read 433 times)

guruevi

  • I’m new here
  • *
  • Posts: 12
  • Karma: 2
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: MariaDB
  • PHP version: 4.5
CiviCRM query/function for 'first time' actions
March 25, 2015, 06:01:40 pm
Hi,

I don't know if there is a core CiviCRM functionality or a 'simple' way of getting an action/activity within CiviCRM on the 'first time' someone does something. Eg. first time event -> activity gets created for that person with the outreach coordinator; first time membership -> activity gets created for the membership coordinator.

I've looked through the documentation and couldn't find anything. I have thought about doing Drupal actions but I don't think that triggers on API inserts and we are heavy users of the REST interface.

Any suggestions are welcome. If I'd have to roll my own, where do I start? The Hook Reference here http://wiki.civicrm.org/confluence/display/CRMDOC/Hook+Reference talks about Drupal (6) modules which, again, Drupal does not seem to come into play when talking through the API.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: CiviCRM query/function for 'first time' actions
March 25, 2015, 07:16:50 pm
You can use CiviCRM hooks in a Drupal module, though I find that civix is very easy to use to build a Civi-native extension.  Also, it's not a bad idea for us to update those examples on the Hook Reference page!

If you're comfortable creating Drupal modules, that's probably easiest - just create a skeletal module, and call hook_civicrm_post. 
Something like:
Code: [Select]
function yourmodulename_civicrm_post($op, $objectName, $objectId, &$objectRef) {
  if($op == "create" && $objectName == "Event") {
    //make an api call here to get a count of events for this person
    //if count == 1 then make an api call to create an activity for the coordinator
  }
}

You seem API-savvy, so I won't belabor the basics of that.  Hope this helps!
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

guruevi

  • I’m new here
  • *
  • Posts: 12
  • Karma: 2
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: MariaDB
  • PHP version: 4.5
Re: CiviCRM query/function for 'first time' actions
March 27, 2015, 04:32:31 pm
My question and I don't see an answer in the docs is whether these Drupal hooks get called when using the REST or Ajax API. I have no trouble implementing a Drupal module but I was hoping for a hook in "Core" so it reacts regardless of whether we call from, Drupal interface, Drush, REST or CRM.api3 in JS.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: CiviCRM query/function for 'first time' actions
March 27, 2015, 04:57:02 pm
Hi guruevi,

Yes, the post hook will fire on API calls.  I've done this a bunch of times - but also, on the postProcess hook docs, it says explicitly:
"This hook is not called when using the API, only when using the regular forms. If you want to have an action that is triggered no matter if it's a form or an API, use the pre and post hooks instead."
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • CiviCRM query/function for 'first time' actions

This forum was archived on 2017-11-26.