Run a logic hook only on new records


I’m using SuiteCRM 7.7.8.

I wrote a logic hook to run on ‘before_save’ but I’m confused on how I can tell if a new record (in my case Opportunity) is being created or if an existing record is being updated. I only want my logic hook to run for newly created records.

Did some Googling and saw that SugarCRM uses a flag “isUpdate” in the logic hooks that is true or false for a new record.

How can one find this information for Suite CRM?

You can use the fetched_row flag to determine this.

//Only execute on new rows
if ($bean->fetched_row == false) {
//Proceed …



Great! That worked! Thanks a lot.

Another question: How can you tell which fields are being updated on a before_save or after_save?

To determine is a field has been changed, you would compare its current value to its fetched row value. Here is an example where I see if the sales stage has been modified…

      if  ($bean->sales_stage != $bean->fetched_row['sales_stage']) {

If you need to check an entire list of fields, you would probably want to put the field names in an array and loop through them as I am doing here:

       $shared_fields = array('proposal_number_c','auto_inquiry_number_c','amount','option_value_c',
        // Then cycle through them
        foreach($shared_fields as $shared_field){
           // do a change detection leveraging the fetched_row value
           if($bean->$shared_field != $bean->fetched_row[$shared_field]) {

Good luck!


Hello Dianna,
How can I check user creating new record or update record in JS?

1 Like