Answers.Body: <p>You can do this in a few ways:</p>
  
  <p>If the legacy table is static, just move the data across into a custom field select option. You'll be happier when it's done. You can do this with a SQL command if there are a lot of options.</p>
  
  <p>If the data in the legacy system is changing, there are two few ways:
  A) Create MySQL triggers to update the values,
  B) Create a batch script to update the options in Civi from the table,</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-22T00:12:48.843Z
Answers.LastActivityDate: 2018-01-22T00:12:48.843Z
Answers.UserDisplayName: JohnFF
Answers.Body: <p>When you create a custom group, it creates a table in the database and each custom field will have a column created in this table. (see table civicrm_custom_group -> table_name and civicrm_custom_field -> column_name)</p>
  
  <p>So i guess the best you could do is to copy the data from your legacy table to the civicrm custom table.</p>
  
  <p>If you need the legacy table for other purpose, you will have to synchronize the data between the two tables. You could use triggers or implement hook_civicrm_custom to get the data pushed to your legacy table every times a new custom value is created in the inserted / updated.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-30T15:41:15.743Z
Answers.LastActivityDate: 2016-05-30T15:41:15.743Z
Answers.UserDisplayName: samuelsov
Answers.Body: <p><a href="https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_custom" rel="nofollow">hook_civicrm_custom</a> isn't really what you're looking for here - that's to take action when data is entered/changed in a custom field, not to configure it.</p>
  
  <p>Check out <a href="https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_fieldOptions" rel="nofollow">hook_civicrm_fieldOptions</a>, which should let you create field options for this field on the fly.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-29T14:15:49.297Z
Answers.LastActivityDate: 2016-08-29T14:15:49.297Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>newby here with a quick question about custom fields. 
  Is it possible to set up a custom field that queries a non-civicrm table?
  Hoping to create an autocomplete dropdown menu that does a SELECT on a legacy table we have.
  Am I looking in the right direction when I browse this page:
  <a href="https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_custom" rel="noreferrer">https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_custom</a>
  ?</p>
  
  <p>Thank you so much!
  johnnyeng</p>
  
Tags: <custom-fields><database><hooks><php><mysql>
Title: Add custom field and populated with array/data from a non-civicrm table
ThreadText: # Add custom field and populated with array/data from a non-civicrm table
  
  (Asked by: username_0 on 2016-03-15)
  
  newby here with a quick question about custom fields.
  Is it possible to set up a custom field that queries a non-civicrm table?
  Hoping to create an autocomplete dropdown menu that does a SELECT on a legacy table we have.
  Am I looking in the right direction when I browse this page:
  <https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_custom>
  ?
  
  Thank you so much!
  username_0
  
  **Tags:** custom-fields, database, hooks, php, mysql
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2018-01-22. Score: 1
  
  You can do this in a few ways:
  
  If the legacy table is static, just move the data across into a custom field select option. You'll be happier when it's done. You can do this with a SQL command if there are a lot of options.
  
  If the data in the legacy system is changing, there are two few ways:
  A) Create MySQL triggers to update the values,
  B) Create a batch script to update the options in Civi from the table,
  
  
  ---
  
  ### Answer by username_2 on 2016-05-30. Score: 0
  
  When you create a custom group, it creates a table in the database and each custom field will have a column created in this table. (see table civicrm\_custom\_group -> table\_name and civicrm\_custom\_field -> column\_name)
  
  So i guess the best you could do is to copy the data from your legacy table to the civicrm custom table.
  
  If you need the legacy table for other purpose, you will have to synchronize the data between the two tables. You could use triggers or implement hook\_civicrm\_custom to get the data pushed to your legacy table every times a new custom value is created in the inserted / updated.
  
  
  ---
  
  ### Answer by username_3 on 2016-08-29. Score: 0
  
  [hook\_civicrm\_custom](https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_custom) isn't really what you're looking for here - that's to take action when data is entered/changed in a custom field, not to configure it.
  
  Check out [hook\_civicrm\_fieldOptions](https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_fieldOptions), which should let you create field options for this field on the fly.
  
  
  ---
  
  