Page 1 of 1

beforeSave Problem

PostPosted: Mon Dec 14, 2009 12:37 pm
by dbaron2
Hello,

I am using a delegate class to set the value of 3 fields in my record before the record is saved. The code reads the previous values for these 3 fields and sets them back to their prior values under certain cirumstances.

The problem is that the code always gets the wrong DB record. It gets the first record every time which is not the correct one. What am I doing wrong?

Code: Select all
    function beforeSave(&$record){
        $db_rec = df_get_record('change_memos', array('change_memo_id'=>$record->val('change_memo_id')));
        if ($db_rec){
            $record->setValue('last_steps', $db_rec->val('last_steps'));
            $record->setValue('last_reminded', $db_rec->val('last_reminded'));
            if ($record->val('workflow_id') == ""){
                $record->setValue('workflow_id', $db_rec->val('workflow_id'));
            }
        }
    }

PostPosted: Mon Dec 14, 2009 1:41 pm
by shannah
Change
Code: Select all
$db_rec = df_get_record('change_memos', array('change_memo_id'=>$record->val('change_memo_id')));

to
Code: Select all
$db_rec = df_get_record('change_memos', array('change_memo_id'=>'='.$record->val('change_memo_id')));


In the first case, if change_memo_id is null or blank, then your query will match any record from the change_memos table. In the second case, if change_memo_id is blank or null, it will only match records where change_memo_id is blank or null.

-Steve

PostPosted: Mon Dec 14, 2009 8:14 pm
by dbaron2
Thanks again! That did the trick.

I noticed that small syntax difference in another posting, but I didn't understand the significance of it.