1

The threads I have seen are from 2009...

Is there a solution for this in 2018?

Something that would dynamically set current date as default?

enter image description here

1 Answer 1

2

I am not sure if this is possible through UI configuration. The form only allows you to enter valid date but not now(), CURRENT_DATE() etc. However it is definitely possible by adding a small code in a extension.

  1. Create and enable a new CiviCRM extension
  2. Implement the hook_civicrm_buildForm in your extension

For the appropriate variable do:

function ext_civicrm_buildForm($formName, &$form) {
  if ($formName == 'REPLACE_WITH_FORMNAME') {
    $defaultDate = [];
    CRM_Utils_Date::getAllDefaultValues($defaultDate);
    $defaults['custom_XXX'] = $defaultDate;
    $form->setDefaults($defaults);
  }
}
5
  • Thanks, but in what file do I input this code? What exact path? Oct 6, 2018 at 22:30
  • You will need to create a extension using Civix and then implement the hook. Oct 6, 2018 at 23:09
  • That sounds a little complicated...when I create a contact, on the bottom of the form is says: "Last Change by: Bruno Vincent (September 11th, 2018 4:43 PM) » " , now what I would like is a filed that shows up in views displaying a datecreated field, how could I do that? Oct 7, 2018 at 0:25
  • I am getting error on civi 5.65, is this still functional ? @PradeepNayak-CircleInt.
    – Tapash
    Sep 18, 2023 at 16:51
  • Nope, that's just the snippet Sep 19, 2023 at 14:42

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.