Default values not working


I am using SugarCRM version I have set default value for a 'date' field as 'today'. But the field still shows only blank space. I have tried 'Quick repair and rebuild', cleared browser cache etc. But the issue still there. I have also tried to set default value for some other type fields, they too, didnt work. Somebody help me. Suggest some solution either through Studio or by editing php code.

Thanks in advance.

- Sudeep

  • Hi Sudeep,

    can you try setting default value through vardefs.

    Here is an sample code for test_date field for opportunities module.



    The same can you try for case.Then make a repair and rebuild.Hope you will be checking this for new record.

  • Hi Ajay

    Thank you for your response. It worked for me in creating a record. But I need this while updating a record. What I am trying to do is to add a date field which will take todays date if the user didnt manually entered a date to that field. If I could fill the date field with current date while editing, it would get stored if the user didnt manually enter a date. Can you help me in this?



  • If you want this(set today value to field) to happen while we saving a record.Then you should try with logichook/workflow.

    If you are trying with logic hook,Then you can check

    test_date_c is empty,then you update test_date_c with today.(this will work for old record).

    If test_date_c is not equal to today and not empty then you should continue.Which means you should not update value for that field.(this will work for new record with user entries)

    Default value will work for new records.Let us know if need more on this.

  • Hi Ajay,

    I have tried to create a workflow. But workflow cant check for date fields. Then what I did is created a dummy text field, set it to fill it with value in our date field by converting to string. Then created a workflow to check whether this text field is empty or not. If this text field is empty, fill the date field with todays date. But workflows in SugarCRM version is not working.  have checked the same on my 6.5 version and it was working. I am not familiar with logic hooks. Can you give an example code for creating logic hooks for this issue? It would be a great help for me.


    - Sudeep

  • Could you try below,

    place the below files respective paths,I just tried for opportunities module


    $hook_version = 1; 
     $hook_array = Array(); 
    // position, file, function 
    $hook_array['before_save'] = Array(); 
        'Updating test_date_c to todays date',


     if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
        class updateTestDate
            function updateTestDateMethod($bean,$event,$arguments){
                      $now = gmdate('Y-m-d');                

    Make a repair and rebuild.

    Hope this helps.

  • Thank you so much Ajay, you are great

    I could solve the issue by following your example. It works well.

    Thank you once again.


    - Sudeep

  • by doing it direct on the vardefs will benefit you when comes to mobile

    $dictionary["Module"]["fields"]["field"]['default'] = 'now';

    but you might see this on mobile 

    but once you click on the "x" it will remove the NAN and you will be able to see the correct current time