Issue with entity\isNew() method failing to retrieve ID

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rabii
    replied
    You are right, id will not be available because all espocrm formula is a before save script which means it is applied before the record is created and saved in db. I think in this case you might want to reach to a afterSave hook which will be perfect for this scenario https://docs.espocrm.com/development/hooks/

    Leave a comment:


  • a.slyzhko
    replied
    Id might not have been initialized yet by the time of execution of this formula script. Do you use before save script or after save workflow?

    Leave a comment:


  • rabii
    replied
    Make sure that the name of the entity is correct (EmployeeInfo) -> you can check the name under administration > Entity Manager > Employee, also you should use AssignedUserId so it should be as below:

    PHP Code:
    if(entity\isNew()) {
        record\create('EmployeeInfo', 'assignedUserId', id, 'joiningDate', datetime\today(), 'baseSalary', 150000);
    }​ 
    

    Leave a comment:


  • Issue with entity\isNew() method failing to retrieve ID


    When I create a user, I want to create a piece of data, but the newly created user.id cannot be obtained.Click image for larger version

Name:	image.png
Views:	224
Size:	28.8 KB
ID:	100927​
Working...