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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Set custom field value from activity date
Pages: [1]

Author Topic: Set custom field value from activity date  (Read 372 times)

FrTommy

  • I post frequently
  • ***
  • Posts: 273
  • Karma: 2
  • CiviCRM version: 4.5.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.5.32
  • PHP version: 5.3
Set custom field value from activity date
September 27, 2014, 03:02:30 pm
I'm trying to set the value of a custom contact field based on when an activity occurred. The activity will be print PDF letter with a subject of "Newcomer Invite Sent". I'm not a coder (at least good enough to write something from scratch) but I can tweak some code if I have something to start from.

Does anyone have some hook code that I could use to do this?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Set custom field value from activity date
September 27, 2014, 04:36:42 pm
Activity date is already recorded. What's the purpose of recording it twice?
Try asking your question on the new CiviCRM help site.

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: Set custom field value from activity date
September 28, 2014, 08:43:48 am
Coleman - I think the answer to "why record it twice?" is because it may need to be used in a Search View, or as a token, or in a report.  I agree that in an ideal world one wouldn't record the data twice - but the limitations of the Civi UI sometimes make it necessary.

FrTommy - You should definitely learn Civix - it will create the skeleton of the extension for you, so you're not writing from scratch! 

After that - I have an extension I wrote that records the first join date of any membership to a custom field - which isn't so different from what you're doing.  I just uploaded it to Github for you: https://github.com/PalanteJon/originaljoindate.  After you create your skeleton extension, look in my originaljoindate.php.

Note that much more important than having code to work from is knowing how to debug!  If I'm writing an extension like this, I'll often throw in
Code: [Select]
CRM_Core_Error::debug('myvariable', $myvariable);
die;

into my code.  If I'm debugging something AJAX-y, I can't tell the code to die; instead, I'll make it log to the log file.  See this page: http://wiki.civicrm.org/confluence/display/CRMDOC/Debugging+for+developers
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

FrTommy

  • I post frequently
  • ***
  • Posts: 273
  • Karma: 2
  • CiviCRM version: 4.5.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.5.32
  • PHP version: 5.3
Re: Set custom field value from activity date
September 28, 2014, 03:23:31 pm
I created a custom field (well two actually). One is Newcomer Invite Sent date and then First time visit date. I want these so I can easily see them without having to search each time. The Newcomer Invite sent date should populate from the date of the Activity with the subject of "Newcomer Invite Sent" the first time visit date would be manually entered.

Where is Civix?

I think i'd rather do a drupal module instead of an extension. It's easier for me. I think I've got how to set the custom field but i'm not sure of the following:
1. which hook to use?
2. when the best time to call the code and how to actually call it....as far as should I call it anytime the activity Print PDF Letter is run?
3. how do I search activities and get the date of the activity with the subject "Newcomer Invite Sent"
« Last Edit: September 28, 2014, 03:40:13 pm by FrTommy »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Set custom field value from activity date

This forum was archived on 2017-11-26.