Hello all,
I apologize - I am new to coding with SuiteCRM and there are some things changed from version to version, that I don’t quite understand yet.
So please bear with me!
So far we used older version of SuiteCRM and we had the following customization in file
/modules/AOS_PDF_Templates/formLetterPdf.php
line 78 (where it was $file_name = str_replace(" ", “_”, $template->name) . “.pdf”
$somecustomvariable01 = 'Not specified';
if($module_type == 'Contacts')
{
$contact = new Contact();
$contact->retrieve($module->id);
$somecustomvariable01 = str_replace(" ","_",$contact->name);
} else{
$account = new Account();
$account->retrieve($object_arr['Accounts']);
$somecustomvariable01 = str_replace(" ","_",$account->name);
}
$file_name = date("Y-m-d").'_'.str_replace(" ","_",$template->name).'_'.$somecustomvariable01.".pdf";
which allowed us to save files via Action->Generate Letter, with file names, depending the module we used include either Account name or Contact name.
After upgrading to the latest SuiteCRM, the current code doesn’t work anymore, as many functions replaced by bean.
We tried some code like the following for some specific Accounts and Contacts IDs
if ($bean->module_dir == 'Accounts') {
$bean01 = BeanFactory::getBean('Accounts', 'b23e226e-05d2-8251-23e3-5887dde4555e');
$somevariable01 = $bean01->name;
$somecustomvariable01 = str_replace(" ","_",$somevariable01);
}
else if ($bean->module_dir == 'Contacts') {
$bean02 = BeanFactory::getBean('Contacts', '9eeqe348-e43c-e324-2242-52425e345a35');
$somevariable02 = $bean02->last_name;
$somevariable04 = $bean02->first_name;
$somecustomvariable01 = str_replace(" ","_",somevariable02).'_'.str_replace(" ","_",$somevariable03);
}
$file_name = date("Ymd").'_'.str_replace(" ", "_", $template->name).'_'.$somecustomvariable01. ".pdf";
And we get the desired filename structure.
We tried to change the ID field (eg the ‘b23e226e-05d2-8251-23e3-5887dde4555e’) so it gets it dynamically, depending the module we were, like
$bean->id
$current_id
$account_id
$contact_id
$this->contact_id
$current_id = $bean->fetched_row[‘id’]
etc, with no success.
Is there a way to get current visited Account or visited Contact ID, in that field, so we get the correct file name?
Thank you in advance!