Answers.Body: <p>This is the reverse of what you're trying to do but might have the intended result:</p>
  
  <p>Instead of populating the custom field <em>after</em> event creation, how about adding the custom field to your event template and populating it there?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-13T18:22:24.807Z
Answers.Text: That's a good idea, I can see how that would work.  But there's a second problem.  I need to be able to programmatically fetch events with the api, but custom data doesn't filter events via api. I was planning on populating a Drupal field using CiviCRM entity 2.x, but to do this I need to be able to get at both bits of data in some hook or another....
Answers.UserDisplayName: jackrabbithanna
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-13T18:28:48.003Z
Answers.Text: i could get at it with: hook_civicrm_custom(), good idea on setting a value for a custom field in the template...
Answers.UserDisplayName: jackrabbithanna
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-13T18:18:53.023Z
Answers.LastActivityDate: 2015-07-13T18:18:53.023Z
Answers.UserDisplayName: Coleman
Body: <p>I'm working on an event management framework where I want to have a set of event templates, and create events based off of those templates. </p>
  
  <p>I'm trying to find a way to get at and store which template a newly created event was derived from but I can't quite figure out what to do. </p>
  
  <p>I tried looking at both 
  hook_civicrm_postProcess() (which has the template_id but not the new event's id)
  and hook_civicrm_post() which as the newly created event id, but doesn't tell you what template it was derived from. </p>
  
  <p>Can anyone think of a way to find those two values at the same time so that I can put the data in a custom field on the new event?</p>
  
Tags: <civievent>
Title: How to store template_id that new event is derived from
ThreadText: # How to store template_id that new event is derived from
  
  (Asked by: username_0 on 2015-07-13)
  
  I'm working on an event management framework where I want to have a set of event templates, and create events based off of those templates.
  
  I'm trying to find a way to get at and store which template a newly created event was derived from but I can't quite figure out what to do.
  
  I tried looking at both
  hook\_civicrm\_postProcess() (which has the template\_id but not the new event's id)
  and hook\_civicrm\_post() which as the newly created event id, but doesn't tell you what template it was derived from.
  
  Can anyone think of a way to find those two values at the same time so that I can put the data in a custom field on the new event?
  
  **Tags:** civievent
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-07-13. Score: 1 | Accepted answer
  
  This is the reverse of what you're trying to do but might have the intended result:
  
  Instead of populating the custom field *after* event creation, how about adding the custom field to your event template and populating it there?
  
  > **Comments:**
  > **username_0**: That's a good idea, I can see how that would work.  But there's a second problem.  I need to be able to programmatically fetch events with the api, but custom data doesn't filter events via api. I was planning on populating a Drupal field using CiviCRM entity 2.x, but to do this I need to be able to get at both bits of data in some hook or another....  
  > **username_0**: i could get at it with: hook_civicrm_custom(), good idea on setting a value for a custom field in the template...  
  
  ---
  
  