In an entity called Project, I want to generate value for fields in a new item in the beforeCreate event. My project model has a field called projectNumber, which is a varchar(10). The values will be stored as YY-NNNN where YY is the two digit year (e.g., 16 for 2016) and NNNN is an incremental value starting from 0001 at the beginning of each year. For example, the first project in 2017 is 17-0001.
In my old API, I handled this in the 'creating' method for those of you who may be familiar with Laravel. Essentially, during the creation of the object, the 'creating' method is called and it does the following operations:
After that code executes, the item is inserted into the database. My problem is I don't know how to do the same thing in EspoCRM. Here's my entity controller:
Any tips would be greatly appreciated.
In my old API, I handled this in the 'creating' method for those of you who may be familiar with Laravel. Essentially, during the creation of the object, the 'creating' method is called and it does the following operations:
Code:
parent::creating(function ($item) { $item->projectNumber = sprintf("%02d-%04d",date('y'),parent::where('year', $year)->max('number') + 1); });
Code:
class Project extends \Espo\Core\Templates\Controllers\BasePlus { public function beforeCreate(Entity $entity, array $data = array()) { $entity->... [COLOR=#FF0000]# What goes here?[/COLOR] } }
Comment