Default values not working

Hi,

I am using SugarCRM version 7.5.2.3. 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

Parents
  • Hi Sudeep,

    can you try setting default value through vardefs.

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

    /custom/Extension/modules/Opportunities/Ext/Vardefs/sugarfield_test_date.php

    $dictionary['Opportunity']['fields']['test_date']['display_default']='now';
    

    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?

    regards,

    -Sudeep

  • 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 7.5.2.3 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.

    regards,

    - Sudeep

Reply
  • 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 7.5.2.3 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.

    regards,

    - Sudeep

Children
  • Could you try below,

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

    /custom/modules/Opportunities/logic_hooks.php

    <?
    $hook_version = 1; 
    
     $hook_array = Array(); 
    // position, file, function 
    $hook_array['before_save'] = Array(); 
    $hook_array['before_save'][]=Array(
        10,
        'Updating test_date_c to todays date',
        'custom/modules/Opportunities/updateTestDate.php',
        'updateTestDate',
        'updateTestDateMethod',
        );
        
    ?>
    

    /custom/modules/Opportunities/updateTestDate.php

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

    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.

    Regards,

    - Sudeep