3

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?

  • 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? – artfulrobot Apr 14 '20 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. – Jon G - Megaphone Tech Apr 15 '20 at 22:30
  • Yeah. thanks, you're right. (But WHY, Civi, WHY!) I fixed it with an api wrapper - see linked question if interested. – artfulrobot Apr 17 '20 at 6:27
0

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?

0

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

  • I'd have assumed that, too, but it does not seem to be the case! – artfulrobot Apr 14 '20 at 10:13
  • but that is not fair.... – ErikH - CiviCooP Apr 14 '20 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. – artfulrobot Apr 14 '20 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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