Results 1 to 2 of 2

Thread: query updating custom field

  1. #1
    dusker is offline Senior Member
    Join Date
    Nov 2008
    Posts
    31

    Default query updating custom field

    Hello,

    i have a pretty complex situation down here.
    in my opportunities module i have several custom fields, and one of them is a computed field (on a database level), so it shouldn't be updated with any query comming from sugar. is it possible to achieve this, because everytime i try to save an opportunity, it obviously tries to save custom fields as well and here's the problem:

    12/10/08 15:28:31 [1380][1][FATAL] SQL Server error: The column "weighted_c" cannot be modified because it is either a computed column or is the result of a UNION operator.
    So the best solution here would be to get sugar not to touch this field (and this field needs to be there because of reporting - lack of weighted value field), but i don't know where the queries are stored. Could anyone help out with this?

    greetings
    peter

  2. #2
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: query updating custom field

    Peter,

    We have a computed field as well in the Accounts module. What we did was rename the Account.php file to Accounts_sugar.php and renamed the class within that file to Accounts_sugar. We then created a new Account.php file with the following contents:
    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once(
    'modules/Accounts/Account_sugar.php');

    /** [IC] 20080711 PDB - Extend the Accounts class to modify the save and
                            retrieve functionality to look at the name_source
                            column instead of name. */
    class Account extends Account_sugar {

        var 
    $name_source;

        function 
    Account() { 
            
    parent::Account_sugar();
        }

        function 
    retrieve($id = -1$encode=true) {

            
    $this->field_defs['name_source'] = $this->field_defs['name'];
            
    $this->field_defs['name_source']['name'] = 'name_source';

            
    parent::retrieve($id$encode);

            
    $this->name $this->name_source;

            return 
    $this;
        }

        function 
    save($check_notify FALSE) {

            
    $this->field_defs['name_source'] = $this->field_defs['name'];
            
    $this->field_defs['name_source']['name'] = 'name_source';
            
    $this->name_source $this->name;
            unset(
    $this->field_defs['name']);

            return 
    parent::save($check_notify);
        }

    }
    ?>
    The name column is a computed column. Pretty much what we did was have a different column display the data on the screen (called name_source) so that name_source is saved and not name.

    Hope that gives you some ideas.

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. Replies: 2
    Last Post: 2007-07-24, 12:22 AM
  3. Replies: 1
    Last Post: 2007-07-23, 03:32 AM
  4. Updating Custom fields via SOAP ?
    By exiges in forum Help
    Replies: 3
    Last Post: 2007-01-04, 03:49 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
  •