Creating new entities in scheduled jobs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bandtank
    Active Community Member
    • Mar 2017
    • 379

    Creating new entities in scheduled jobs

    Is there an example of how to create a new entity in a scheduled job? I see a lot of examples of DELETE and SELECT, but I need to insert new rows. Basically, it would be like clicking the 'Create xxxxxx' button in the UI and then filling out some fields before hitting save. I think I need to use getEntityManager or getEntity, but I can't find any documentation or tutorials explaining how either of those functions work.

    I'm trying to create a 'Timesheet' entity for each user who has 'hasTimesheet' = true in their 'User' object. In pseudocode:

    Code:
    for each user where user.hasTimesheet = true:
        create new Timesheet and set a few fields
        save timesheet
    Last edited by bandtank; 10-26-2017, 08:12 PM.
  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #2
    Hello
    Not sure, I understand you right
    About Entity Manager https://www.espocrm.com/documentation/development/orm/
    If you want to create a job, which you can schedule with UI, this link will help you https://www.espocrm.com/documentatio...scheduled-job/
    if you want to create a job once in code
    Code:
      
                   $job = $this->getEntityManager()->getEntity('Job');
                    $job->set(array(
                        'serviceName' => $serviceName,
                        'methodName' => $methodName,
                        'data' => array('someVar' => 'someValue'),
                        'executeTime' => date('Y-m-d H:i:s'),
                    ));
                    $this->getEntityManager()->saveEntity($job);
    Last edited by tanya; 01-29-2018, 03:49 PM.

    Comment

    • bandtank
      Active Community Member
      • Mar 2017
      • 379

      #3
      I was looking for all of that information. Thanks for your help.

      Comment

      • cardmaverick
        Member
        • Jan 2018
        • 30

        #4
        message moved.
        Last edited by cardmaverick; 01-27-2018, 12:08 AM.

        Comment

        Working...