Answers.Body: <p>I ran into a similar issue of custom tokens not populating for scheduled reminders. The workaround in <a href="https://issues.civicrm.org/jira/browse/CRM-11153?focusedCommentId=83503&amp;page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-83503" rel="nofollow">Brian Shaughnessy's comment</a> on <a href="https://issues.civicrm.org/jira/browse/CRM-11153" rel="nofollow">CRM-11153</a> fixed it for me:</p>
  
  <blockquote>
    <p>early in tokenValues put:</p>
  </blockquote>
  
  <pre><code>$single = false;
  if (!is_array($contactIDs)) {
      $contactIDs = array( $contactIDs );
      $origValues = $values;
      $single = true;
  }
  </code></pre>
  
  <blockquote>
    <p>then at the very bottom put:</p>
  </blockquote>
  
  <pre><code>if ($single) {
      $values = $origValues + $values[$id];
  }
  </code></pre>
  
  <p><code>$id</code> may be something different in your hook implementation.</p>
  
  <p>Other recent comments on that issue suggest that a fix may find its way into CiviCRM core.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-18T17:58:13.900Z
Answers.LastActivityDate: 2016-01-18T17:58:13.900Z
Answers.UserDisplayName: davejenx
Body: <p>I have the same problem as at <a href="http://forum.civicrm.org/index.php/topic,32608" rel="nofollow">http://forum.civicrm.org/index.php/topic,32608</a></p>
  
  <p>I have created a tokenValues hook to fetch the value of a field from a multi-record custom field set.  I have the token hook embedded within a message template.  The hook works fine and correctly populates the value if I trigger it from Actions->Send an email.  But when triggered by a Scheduled Reminder based on x days before end of membership, the value is not filled in within the email that goes out.</p>
  
  <p>I have logging within the token hook which shows that the hook <em>is</em> being called and is populating the returned array with the correct value.  I tried to debug further, but I can't figure out from where the tokenValues function is being called.  So I can't figure out why the behavior is different for Action->Send an email vs Scheduled Reminders.</p>
  
  <p>If necessary, I can work around this by running a script to push the value I want into a non multi-record field, as regular custom fields work fine.  But obviously that's a bit of a cludge, and this seems like a bug in CiviCRM.</p>
  
  <p>This is a different issue than that described at  <a href="https://civicrm.stackexchange.com/questions/2215/token-not-evaluating-in-civimail">Token not evaluating in CiviMail</a> - that's discussing custom field permissions, which aren't a problem here.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-27T15:27:19.557Z
Comments.Text: I forgot to mention: the tokenValues hook, when called, is passed a $context value of 'CRM_Activity_BAO_Activity'
Comments.UserDisplayName: Norris
Tags: <email><tokens><hooks><message-templates>
Title: Can tokenValue hooks be used in scheduled reminder emails?
ThreadText: # Can tokenValue hooks be used in scheduled reminder emails?
  
  (Asked by: username_0 on 2015-06-27)
  
  I have the same problem as at <http://forum.civicrm.org/index.php/topic,32608>
  
  I have created a tokenValues hook to fetch the value of a field from a multi-record custom field set. I have the token hook embedded within a message template. The hook works fine and correctly populates the value if I trigger it from Actions->Send an email. But when triggered by a Scheduled Reminder based on x days before end of membership, the value is not filled in within the email that goes out.
  
  I have logging within the token hook which shows that the hook *is* being called and is populating the returned array with the correct value. I tried to debug further, but I can't figure out from where the tokenValues function is being called. So I can't figure out why the behavior is different for Action->Send an email vs Scheduled Reminders.
  
  If necessary, I can work around this by running a script to push the value I want into a non multi-record field, as regular custom fields work fine. But obviously that's a bit of a cludge, and this seems like a bug in CiviCRM.
  
  This is a different issue than that described at [Token not evaluating in CiviMail](https://civicrm.stackexchange.com/questions/2215/token-not-evaluating-in-civimail) - that's discussing custom field permissions, which aren't a problem here.
  
  **Tags:** email, tokens, hooks, message-templates
  
  > **Comments:**
  > **username_0**: I forgot to mention: the tokenValues hook, when called, is passed a $context value of 'CRM_Activity_BAO_Activity'  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-18. Score: 3 | Accepted answer
  
  I ran into a similar issue of custom tokens not populating for scheduled reminders. The workaround in Brian Shaughnessy's comment on CRM-11153 fixed it for me:
  
  early in tokenValues put:
  
  $single = false;
  if (!is_array($contactIDs)) {
      $contactIDs = array( $contactIDs );
      $origValues = $values;
      $single = true;
  }
  
  
  then at the very bottom put:
  
  if ($single) {
      $values = $origValues + $values[$id];
  }
  
  $id may be something different in your hook implementation.
  Other recent comments on that issue suggest that a fix may find its way into CiviCRM core.
  
  
  ---
  
  