2

When you set a default value for a custom field, it only exists at the form level. Is there a practical way to enforce them at the database level? For instance, by altering the SQL table definition?

I understand that a custom field record isn't created under every circumstance, but if I account for that (e.g. another custom field in that group is always populated) is altering the SQL practical?

3
  • Hi, did you ever find a solution to this? my similar question has more on this. You mention that custom field records are not always created - do you know why? Commented Apr 14, 2020 at 10:15
  • @artfulrobot I believe that if you create, e.g, a new contact, but don't populate any of the custom field values in a group, the record isn't created in the corresponding table. This may only be true via API though, I'm not sure. Commented Apr 15, 2020 at 22:30
  • Yeah. thanks, you're right. (But WHY, Civi, WHY!) I fixed it with an api wrapper - see linked question if interested. Commented Apr 17, 2020 at 6:27

2 Answers 2

1

A possible downside, although unlikely, is an upgrade might do some kind of batch modify on all custom fields that would wipe your default value.

What are you trying to do that can't be done with a hook or trigger?

1

Hang on, there is a default_value column in the civicrm_custom_field table? I would assume changing that value would actually work....

3
  • I'd have assumed that, too, but it does not seem to be the case! Commented Apr 14, 2020 at 10:13
  • but that is not fair.... Commented Apr 14, 2020 at 12:27
  • I found a fix using api wrapper. It's not pretty esp as it now requires different implementations for api3 and api4. Commented Apr 14, 2020 at 13:41

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.