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! johnnyeng

3 Answers 3


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,


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.


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, which should let you create field options for this field on the fly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.