Additional Logic in module save

It would appear that when AOW saves a record as part of the Create Record Action that its not firing the parent::save which would then invoke any business logic. Why is this please? Its essential for any new records to be added in the same way and respectfully of, the normal sugarcrm processes.

Its my belief that you need to add $record->save after the line $record->$field->add($rel_id); in actionCreateRecord.php in order to kick off any custom business logic after running the relationship as I have created a custom save action (not finished yet like:

require_once(‘modules/clt_client_doc_item/clt_client_doc_item_sugar.php’);
class clt_client_doc_item extends clt_client_doc_item_sugar {

function clt_client_doc_item(){
	parent::clt_client_doc_item_sugar();
}

function save($check_notify = FALSE) {
    parent::save($check_notify);
    $this->parent_type = $this->clt_module_name;
    switch ($this->clt_module_name) {
        case "clt_client_header":
            $client_header = $this->get_linked_beans("clt_client_doc_item_clt_client_header", "clt_client_doc_item");
                $this->parent_id = $client_header[0]->id;
            }
            break;
        case "clt_client_profile":
            break;
        case "clt_client_owner":
            break;
        case "clt_client_controller":
            break;
        case "clt_client_relationship":
            break;

    }
    parent::save($check_notify);
}

}

Hmm no that doesnt appear to work. If I run a “create record” action then the link takes place and relationship created, however I use a custom save to populate the value of a flex relate field, but that doesnt work until I open the “created record” and save it again. This should fire automatically as part of the createRecord action.

Nobody? :frowning:

Could you post the workflow? If you would like to trigger the save on the parent record and it does not appear to be working you could add a flag field which is only edited by the workflow and causes the parent record to be saved.

I am sorry you haven’t had a response earlier, with the 7.3 release I think everyone at Suite might be very busy at the moment.

1 Like

Thanks for the response, yes I can see the team have been very busy and I am certainly so happy they are continuing SugarCRM CE and praise the efforts made thusfar. I have attached the workflow screenshots below. Essentially the client_doc_item table is connected to one of 5 other custom module tables, this relationship is displayed as a flex relate field to the custom module; however AOW does NOT pick up the custom module to show in the drop down so I have to use a linking field to reflect the relationshop through module builder relationship tables.

The related table from the workflow populates okay, but the custom code in the custom module diectory does not fire. When I open the the module and save the record in CRM it populates the flex relate field just fine, just not as part of the workflow “create record” action.


<?PHP
/*********************************************************************************
 * SugarCRM Community Edition is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by SugarCRM".
 ********************************************************************************/

/**
 * THIS CLASS IS FOR DEVELOPERS TO MAKE CUSTOMIZATIONS IN
 */
require_once('modules/clt_client_doc_item/clt_client_doc_item_sugar.php');
class clt_client_doc_item extends clt_client_doc_item_sugar {

	function clt_client_doc_item(){
		parent::clt_client_doc_item_sugar();
	}

    function save($check_notify = FALSE) {
        parent::save($check_notify);
        $this->parent_type = $this->clt_module_name;
        switch ($this->clt_module_name) {
            case "clt_client_header":
                $client_header = $this->get_linked_beans("clt_client_doc_item_clt_client_header", "clt_client_doc_item");
                $this->parent_id = $client_header[0]->id;
                break;
            case "clt_client_profile":
                break;
            case "clt_client_owner":
                break;
            case "clt_client_controller":
                break;
            case "clt_client_relationship":
                break;
        }
        if (!isset($this->ignore_update_c) || $this->ignore_update_c === false) {
            $this->ignore_update_c = true;
            parent::save($check_notify);
        }
    }

}
?>

Perhaps you could provide some clarity on your proposed solution please?

The custom save function just doesnt fire, and I tried to implement a custom retrieve function to carry out the same change but it creates an endless loop which then times out. I cant help but think the easiest way is to correct AOW so it forces the business logic through the correct use of the save function.