Answers.Body: <p>How about modifying the core event code to also suck in the event custom fields before sending it to the templates. In general, especially for specific events (and contributions etc), including custom fields seems a good thing (and potentially not very expensive from a query perspective)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-06T14:15:13.973Z
Answers.Text: Did this ever see the light of day?
Answers.UserDisplayName: Graham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-10T14:59:48.347Z
Answers.Text: We're making progress on this!
  
  We've made a custom extension that seems to work quite well. We're in testing phase now and will post the extension for comment in GitHub when we get a mo...
Answers.UserDisplayName: Andyg8
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-15T03:33:59.687Z
Answers.LastActivityDate: 2015-04-15T03:33:59.687Z
Answers.UserDisplayName: Donald Lobo
Answers.Body: <p>I think your second idea can be made to work:</p>
  
  <blockquote>
    <p>Or we could intervene here: hook_civicrm_tokenValues() But at this point we no longer know for which event we need to get the additional custom field data from.</p>
  </blockquote>
  
  <p>As far as I can tell, the parameters passed into this hook during the processing of a Scheduled Reminder actually do include the event ID -- the structure is just a little off as discussed <a href="https://civicrm.stackexchange.com/questions/3573/can-tokenvalue-hooks-be-used-in-scheduled-reminder-emails?rq=1">elsewhere</a>.</p>
  
  <p>Here's an implementation that provides the value of a custom field:</p>
  
  <pre><code>/**
  * Populates a token named "mytoken" with the value from a custom field 
  * (id 123) for use in Scheduled Reminders
  * Implements hook_civicrm_tokenValues().
  */
  
  function foo_civicrm_tokenValues(&amp;$values, $cids, $job = null, $tokens = array(), $context = null) {
  static $events = array();
  
    if (is_numeric($cids)) {
      // We're being called by CRM/Core/BAO/ActionSchedule.php:465
      // Params are structured differently than they're supposed to be, but we 
      // can work with it. See https://civicrm.stackexchange.com/questions/3573/can-tokenvalue-hooks-be-used-in-scheduled-reminder-emails
  
      if ($event_id = CRM_Utils_Array::value('event.event_id', $values)) {
        // We've been passed an event ID
  
        if (!array_key_exists($event_id, $events)) {
          // We haven't looked up the custom field value yet
  
          // Fetch the custom field value from the database
          $event = civicrm_api3('Event', 'getsingle', array(
            'sequential' =&gt; 1,
            'return' =&gt; "custom_123",
            'id' =&gt; $event_id,
          ));
  
        $val = CRM_Utils_Array::value('custom_123', $event);
  
        // Keep this value in memory to use with the other event participants
        $events[$event_id] = $val;
  
        } else {
          // We stored the value previously
          $val = $events[$event_id];
        }
  
        $values['event.mytoken'] = $val;
      }
    }
  }
  </code></pre>
  
  <p>Note: event information is not passed to the hook for additional (non-participant) recipients of the Scheduled Reminder.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-05T07:47:41.610Z
Answers.LastActivityDate: 2016-04-05T07:47:41.610Z
Answers.LastEditDate: 2017-04-13T12:53:13.017Z
Answers.UserDisplayName: Noah Miller
Body: <p>We've done some investigation and found two places we could intervene to make this possible:</p>
  
  <ol>
  <li><p>Intervene here: CRM_Core_BAO_ActionSchedule::sendMailings(), but to make tokens available we'd have to collect all custom field info for a specific event. This would possibly be very database heavy, and further, it can't be optimised for when only a (small) specific subset of tokens are used in the scheduled reminder.</p></li>
  <li><p>Or we could intervene here: hook_civicrm_tokenValues()
  But at this point we no longer know for which event we need to get the additional custom field data from.</p></li>
  </ol>
  
  <p>So, what to do? Any ideas? Thanks for your help!</p>
  
Tags: <email><custom-fields><tokens><civievent>
Title: How can we make Event custom fields available as tokens for scheduled reminders?
ThreadText: # How can we make Event custom fields available as tokens for scheduled reminders?
  
  (Asked by: username_0 on 2015-04-14)
  
  We've done some investigation and found two places we could intervene to make this possible:
  
  1. Intervene here: CRM\_Core\_BAO\_ActionSchedule::sendMailings(), but to make tokens available we'd have to collect all custom field info for a specific event. This would possibly be very database heavy, and further, it can't be optimised for when only a (small) specific subset of tokens are used in the scheduled reminder.
  2. Or we could intervene here: hook\_civicrm\_tokenValues()
     But at this point we no longer know for which event we need to get the additional custom field data from.
  
  So, what to do? Any ideas? Thanks for your help!
  
  **Tags:** email, custom-fields, tokens, civievent
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-04-15. Score: 2
  
  How about modifying the core event code to also suck in the event custom fields before sending it to the templates. In general, especially for specific events (and contributions etc), including custom fields seems a good thing (and potentially not very expensive from a query perspective)
  
  > **Comments:**
  > **username_0**: We're making progress on this!  We've made a custom extension that seems to work quite well. We're in testing phase now and will post the extension for comment in GitHub when we get a mo...  
  > **username_2**: Did this ever see the light of day?  
  
  ---
  
  ### Answer by username_3 on 2016-04-05. Score: 2
  
  I think your second idea can be made to work:
  
  > Or we could intervene here: hook\_civicrm\_tokenValues() But at this point we no longer know for which event we need to get the additional custom field data from.
  
  As far as I can tell, the parameters passed into this hook during the processing of a Scheduled Reminder actually do include the event ID -- the structure is just a little off as discussed [elsewhere](https://civicrm.stackexchange.com/questions/3573/can-tokenvalue-hooks-be-used-in-scheduled-reminder-emails?rq=1).
  
  Here's an implementation that provides the value of a custom field:
  
  ```
  /**
  * Populates a token named "mytoken" with the value from a custom field 
  * (id 123) for use in Scheduled Reminders
  * Implements hook_civicrm_tokenValues().
  */
  
  function foo_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
  static $events = array();
  
    if (is_numeric($cids)) {
      // We're being called by CRM/Core/BAO/ActionSchedule.php:465
      // Params are structured differently than they're supposed to be, but we 
      // can work with it. See https://civicrm.stackexchange.com/questions/3573/can-tokenvalue-hooks-be-used-in-scheduled-reminder-emails
  
      if ($event_id = CRM_Utils_Array::value('event.event_id', $values)) {
        // We've been passed an event ID
  
        if (!array_key_exists($event_id, $events)) {
          // We haven't looked up the custom field value yet
  
          // Fetch the custom field value from the database
          $event = civicrm_api3('Event', 'getsingle', array(
            'sequential' => 1,
            'return' => "custom_123",
            'id' => $event_id,
          ));
  
        $val = CRM_Utils_Array::value('custom_123', $event);
  
        // Keep this value in memory to use with the other event participants
        $events[$event_id] = $val;
  
        } else {
          // We stored the value previously
          $val = $events[$event_id];
        }
  
        $values['event.mytoken'] = $val;
      }
    }
  }
  
  ```
  
  Note: event information is not passed to the hook for additional (non-participant) recipients of the Scheduled Reminder.
  
  
  ---
  
  