Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:	86
Size:	28.8 KB
ID:	100927

  • #2
    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);
    }
    ​ 

    Comment


    • #3
      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?

      Comment


      • #4
        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/

        Comment

        Working...
        X