Results 1 to 4 of 4

Thread: Custom fields aren't created or updated for some accounts

  1. #1
    rbooz is offline Sugar Community Member
    Join Date
    Feb 2006
    Posts
    36

    Exclamation Custom fields aren't created or updated for some accounts

    I upgraded a Sugar 4.2.1a release last week to 4.5.0c and just noticed an interesting issue. For all new accounts and some old accounts, all of our custom fields are ignored when saving the edit form. In the case of a new account, no "accounts_cstm" record is created and no information from our custom fields is saved. If we try to update the fields, they continually come back blank after clicking "save". On pre-existing accounts, some of them will save the data just fine, some of them will not. I can't see any reason between one that works and one that doesn't that would necessitate the problem.

    I've tried to run through the code to see if something is wrong - looked at the log, nothing. Obviously this is a pretty big issue for us as the custom fields contain business critical information on our accounts.

    Just for additional information, I did go back and create a record for one of the new accounts in "accounts_cstm" just to see if Sugar would then update it. Still no go.

    I'd be most appreciative for any help on where to look for a resolution on this. We've been using Sugar for almost a year and have never had problems on this kind of basic issue. Would love some help.

    Thanks!

    Sugar Version: 4.5.0c
    Sugar Edition: Open Source
    Category: Accounts
    Operating System: Windows Server 2003
    PHP Version: 5.1.2
    Database:MySQL 5.0.24a
    Web Server: IIS 6

  2. #2
    rbooz is offline Sugar Community Member
    Join Date
    Feb 2006
    Posts
    36

    Default Re: Custom fields aren't created or updated for some accounts

    After about three hours of working through the code and using a lot of DEBUG messaging, I figured out the problem - and it's something that should probably be looked at by Sugar team. Looking through the 4.5.0f patch, it doesn't appear to be fixed yet. Basically, custom fields saved via the "DynamicFields" module - not by the "SugarBean". If you look at the "save()" method of DynamicFields, it doesn't take into account how to handle fields if they are set to a "zero length" value. That is, when you save a form, it appears that all fields get assigned, even if they are blank. The "SugarBean" takes care of weeding out (setting to NULL) any values that were not filled in on the form. However, the "DynamicFields" module doesn't do this. SO, all of your custom fields get set as blank - which isn't a huge deal for string fields in the DB (although NULL would be better) - but it's a HUGE deal for dates. A blank insert ('') isn't permissible. That's why these fields were failing. This must be some new behavior in 4.5, because we never had this problem in 4.2 and earlier.

    To fix this, I simply took the logic in the save() method of SugarBean and applied it to the save() method of the DynamicFields module. Staring at line 209 (in Sugar 4.5.0c) of "DynamicFields" - here is the edit:

    PHP Code:
                    if(isset($this->bean->$name)){
                        
    //Added Ryan Booz
                        
    if(strlen($this->bean->$name) <= 0) {
                            if(!
    $isUpdate && isset($field['default']) && (strlen($field['default']) > 0)) {
                                    
    $this->bean->$name $field['default'];
                                }
                                else {
                                    
    $this->bean->$name null;
                                }
                        }
                            if(
    is_null($this->bean->$name)) {
                                
    $value "null";
                            }
                            else {
                                
    $value "'".PearDatabase::quote(from_html($this->bean->$name))."'";
                            }
                            
                            if(
    $isUpdate){
                                if(
    $first){
                                    
    $query .= " $name=$value";
                                    
                                }else{
                                    
    $query .= " ,$name=$value";
                                }
                            }
                            
    $first false;
                            
    $queryInsert .= " ,$name";
                            
    $values .= " ,$value";
                        } 
    This follows the logic in Sugarbean that if the value is empty it gets set to NULL or the default Sugar vaule in the UPDATE or INSERT statement. After these edits, my problem is fixed.

  3. #3
    Join Date
    Feb 2006
    Posts
    9

    Default Re: Custom fields aren't created or updated for some accounts

    Oh thank you!!!!! That's been plaguing me for a while.

  4. #4
    rbooz is offline Sugar Community Member
    Join Date
    Feb 2006
    Posts
    36

    Default Re: Custom fields aren't created or updated for some accounts

    I'm glad I could actually contribute something for once, rather then simply asking for help. :-)

Thread Information

Users Browsing this Thread

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

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
  •