AnsweredAssumed Answered

Case Number will be AUTO GENERATED Upon Save

Question asked by john Fieldsend on May 21, 2019
Latest reply on Jul 23, 2019 by john Fieldsend

hi all, just trying to understand the logic of sugar, I have a custom endpoint to create a case

 

public function CreateACase($api, $args) {
global $db;
global $current_user;
$result = array(
'id' => '',
'success' => false,
'errors' => 'Invalid Parameteres',
'args' => $args,
'user' => $current_user->fetched_row['region_c'],
);

$casebean = BeanFactory::getBean("Cases");
$casebean->contact_id = $args['ContactId'];
$casebean->status = $args['Status'];
$casebean->caseorigin_c = $args['Origin'];
$casebean->description = $args['Description'];
$casebean->issue_description_155_c = $args['Description'];
$casebean->customersstatedissue_c = $args['Subject'];
$casebean->contact_id1_c = $args['ContactId'];
$casebean->s_serialnumber_cases_1s_serialnumber_ida = $args['Serial_Number__c'];

$casebean->save();

$bean = BeanFactory::retrieveBean('Cases', $casebean->id);
if(!empty($bean)) {
$result['function'] = __CLASS__;
$result['id'] = $casebean->id;
$result['case'] = $bean->name;
$result['success'] = true;
$result['errors'] = [];
}
return $result;
}

 

this is creating the case as expected via the api, the problem is the developer before me created an after save hook to generate the case number

 

$hook_array['after_save'][] = Array(1,'Case Number','custom/modules/Cases/casehooks.php','casehooks','setCaseNumber',);

 

I thought this would fire when I did $casebean->save(); then I would be able to get the generatedcase number and return to the user with $bean = BeanFactory::retrieveBean('Cases', $casebean->id); I get the b=new case id returned fine but the name always comes back with "Case Number will be AUTO GENERATED Upon Save". I assume that the after_save hook hasn't yet fired so I don't understand how I retrieve the the new case name and get the after save hook to fire

Outcomes