AnsweredAssumed Answered

Custom Case Number

Question asked by Chris Tucker on Apr 24, 2015
Latest reply on Apr 29, 2015 by makumiran
SugarCRM CE v6.5.20
I've created a custom text field in SugarCRM's Cases module called custom_case_number_c. It's a text field. The formated case number will be 201500001 for the first case in the year 2015, 201500002 for the second, and so on. I'm trying to write a logic hook to calculate the case number. I'm confused on this $bean thing. So far, I have this:
class CaseNumber {    function newCaseNumber($bean, $event, $arguments)        {        //Query CASES table for the last Case Record      $case_id = $bean->id;      $query = 'SELECT MAX(cases_cstm.custom_case_number_c) AS casenum FROM cases_cstm LIMIT 1';      $results = $bean->db->query($query, true);      $row = $bean->db->fetchByAssoc($results);      $last_case = $row['casenum'];        //Determine the year      $last_case_year = substr($last_case, 0, 4);      $current_year = date('Y');        //Calculate the case number      $last_case_series = substr($last_case, 4, 9);      if($last_case_year == $current_year){          $new_case = $last_case + 1;      }else{          $new_case = $current_year . '00001';      }        //Set the value        }  }  

First issue: I don't think I'm taking full advantage of this $bean object. Am I calling up the last record in the DB correctly?

Second: How to save it properly and have the ID in the cases_cstm table (which contains that custom field) match the cases table.

Thanks in advance for any help!

Outcomes