Results 1 to 7 of 7

Thread: Custom Date Fields Not Saving Correctly

  1. #1
    1kether1 is offline Sugar Community Member
    Join Date
    Jan 2007
    Posts
    11

    Default Custom Date Fields Not Saving Correctly

    I'm on 4.50 h, SQL server express 2005, php 5.14.

    Dates are completely messed up. For example, a date saved as 06/01/2007 in edit view becomes transformed to 06/24/1905 in detail view. A date saved as 06/02/2007 in edit view is transformed to 06/23/1905. Clicking "Edit" then clicking "Save" *without changing a thing* makes the date change again--from 06/24/1905 to 02/19/1905! Doing that again changes the date to 02/28/1905; one more time sends it back to 02/19/1905, and subsequent "edit"s and "save"s oscilate the values from 02/28/1905 to 02/19/1905. This is in the Leads module. I imagine it happens in other modules as well.

    Does anyone know what's going on here, and how to fix this? I could sure use some help--I've been messing with date problems for the past 3 days now. Values for "Date Created" and "Last Modified" are completely correct--it's only the custom date fields that are screwed up.

    Many thanks in advance if you can help me!

    Louis
    Last edited by 1kether1; 2007-02-01 at 12:13 AM.

  2. #2
    1kether1 is offline Sugar Community Member
    Join Date
    Jan 2007
    Posts
    11

    Default Re: Custom Date Fields Not Saving Correctly

    Interesting development...

    In Modules/DynamicFields/DynamicField.php, I had changed line 210 to read

    Code:
    if(isset($this->bean->$name)){
                    	$quote = "'";
                    	//  Edit by Lou  Added '|| data_type == date' below
                      	if($field['data_type'] == 'int' || $field['data_type']== 'float' || $field['data_type']== 'date'){
                      	//  End edit by Lou
                                   $quote = '';
                                   if(empty($this->bean->$name) && !is_numeric($this->bean->$name) ){
                                           if(strcmp($field['required_option'], 'required') == 0){
                                                   $this->bean->$name  = 0;
                                           }else{
                                                   $this->bean->$name = 'NULL';
                                           }
                                   }
                           }
    so that NULL would be passed in to sql-server as an empty date value instead of an empty string. The reason for this was to keep sql server from defaulting to the date 01/01/1900 12:00:00 AM when an empty string was submitted. Without this, all of my Date custom fields on a form were being saved as 01/01/1900 if no values were explicitly entered, this is just what sql server does for some reason...

    That hack worked fine to keep sql-server's default date from showing up in detail view after editing and saving a form, and I thought I had the problem licked.

    I went back in and took out the hack, leaving the code in its original form, and now, dates I enter in custom fields are being saved correctly, but all of the other custom dates on the form that are left blank are defaulting to that 01/01/1900.

    It seems that sql-server needs some value date instantiated first for the date functions in SUGAR to operate properly.

    So here's my question: does anyone know how to keep that 01/01/1900 from showing up in custom date fields that are left empty? In other words, something like, if(date_value == 01/01/1900){ Do not display value;}

    What file would need to be changed where to include a conditional similar to that pseudocode? I know, it's an ugly way to do things, but at this point, I'm pretty desperate for a quick fix, and I'm green at coding on top of it....

    Many thanks for help,
    Louis


    Windows XP sp2
    IIS 5.1
    SQL Server 2005 Express
    PHP 5.14
    Sugar 4.5.0h

  3. #3
    kbrill's Avatar
    kbrill is offline SugarCRM PS Engineer
    Join Date
    Jul 2004
    Location
    St Louis, MO
    Posts
    3,183

    Talking Re: Custom Date Fields Not Saving Correctly

    Sure, just go to the bean file (for example Contacts.php for contacts module) and look for a function called fill_in_additional_detail_fields(). In that function add the line
    Code:
     if(strstr($focus->date_field,"1900")!==FALSE) {
        $focus->date_field="";
     }
    This code just looks for the string '1900' in the date field and empties the field if '1900' exists. You would have to put one of these for each of your custom fields. Just replace date_field with the name of your custom field. For example if your custom field is named 'current_date' then the name of your field here woudl be 'current_date_c'. Make note of the '_c' at the end.

    You may have to add this code to the fill_in_additional_list_fields() function as well.

    I have not tested this but I think it will work, I hope it helps. Let me know.
    Kenneth Brill - Help Forum Moderator

    I do not respond to 'Private Messages'. Please email me directly instead

    When asking for help, PLEASE give us your Server Information and Version Numbers as asked for on the 'Post New Message' screen as well as any JavaScript errors shown at the bottom of the browser window.
    Help us Help You

  4. #4
    1kether1 is offline Sugar Community Member
    Join Date
    Jan 2007
    Posts
    11

    Default Re: Custom Date Fields Not Saving Correctly

    Rats...

    I put your code in both functions, substituting a real date field_c in for "date_field," and it didn't work. Same behavior as before--1900-01-01 still shows up. I also put != instead of !== to see if maybe that was it, but it didn' matter. Thanks for giving it a shot though--anything else you can think of that might do the trick?

    Louis

  5. #5
    kbrill's Avatar
    kbrill is offline SugarCRM PS Engineer
    Join Date
    Jul 2004
    Location
    St Louis, MO
    Posts
    3,183

    Default Re: Custom Date Fields Not Saving Correctly

    Quote Originally Posted by 1kether1
    Rats...

    I put your code in both functions, substituting a real date field_c in for "date_field," and it didn't work. Same behavior as before--1900-01-01 still shows up. I also put != instead of !== to see if maybe that was it, but it didn' matter. Thanks for giving it a shot though--anything else you can think of that might do the trick?

    Louis
    It has to be !== to work at all. hmmm, I'm sorry I didnt look at the function first. Change $focus to $this, and it should work.
    Kenneth Brill - Help Forum Moderator

    I do not respond to 'Private Messages'. Please email me directly instead

    When asking for help, PLEASE give us your Server Information and Version Numbers as asked for on the 'Post New Message' screen as well as any JavaScript errors shown at the bottom of the browser window.
    Help us Help You

  6. #6
    1kether1 is offline Sugar Community Member
    Join Date
    Jan 2007
    Posts
    11

    Default Re: Custom Date Fields Not Saving Correctly

    Yeehah!!!! Thanks Ken!

    I changed $focus to $this in both functions and it works great!

    Now I've got my work cut out for me -- 60something custom dates to fix, but at least they're fixable!

    Is there a way to make that code apply to every custom date field in the module? Maybe, $this->*_c if ($this->data_type == 'date')? I know it wouldn't be that, but maybe something like it?

    Louis

  7. #7
    sidh211 is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    126

    Default Re: Custom Date Fields Not Saving Correctly

    Hi

    I am using Sugar ce 4.5.1

    I had created one custom date field in account module and set its default value to none.But when i try to create new account that custom date field gets auto populated to 1970-01-01 but in database it stores null value when date is 1970-01-01.
    But actually i want this date field to be blank when i create new record.

    Plss help me out

    Thanks & regds

    sid

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Saving and updating custom fields data
    By jones70 in forum Developer Help
    Replies: 2
    Last Post: 2011-10-05, 06:10 AM
  2. Custom Fields not saving
    By messir in forum Help
    Replies: 1
    Last Post: 2006-08-22, 12:59 PM
  3. Asterisk Patch 1.1.0 Crash on logon
    By skyracer in forum Help
    Replies: 6
    Last Post: 2006-07-08, 06:30 AM
  4. Replies: 7
    Last Post: 2006-06-06, 07:56 PM
  5. Replies: 4
    Last Post: 2005-09-12, 03:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •