Announcement

Collapse
No announcement yet.

Creating new entities in scheduled jobs

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

  • 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.

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


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

      Comment


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

        Comment

        Working...
        X