Accessing getRecordService() in a Hook

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kurt
    Member
    • Jan 2018
    • 37

    Accessing getRecordService() in a Hook

    I'm trying to write a User afterSave hook that will allow me to create a related entity that has a Document as an attachment

    It first successfully grabs the document I would like to attach, and then I had hoped I could just do the following, which is partially borrowed from the Document controller/service code (bolded part):

    $doc = $this->getEntityManager()->getRepository('Document')->order('createdAt', 'DESC')->findOne();
    $attachment = $doc->getRecordService()->getAttachmentList($doc->id)->getValueMapList();
    $tos = $this->getEntityManager()->getEntity('TermsOfService');
    $tos->set(array(
    'name' => 'Terms of Service',
    'termsId' => $attachment->id,
    'assignedUserId' => $entity->id
    ));
    $this->getEntityManager()->saveEntity($tos);

    But $doc ->getRecordService() fails because it's not found...is there some other way to get a reference to the Document getRecordService function, or any other recommended way to get the attachment ID so I can create this other TermsOfService entity with it?

    Thanks.
  • Kurt
    Member
    • Jan 2018
    • 37

    #2
    I was able to figure this out by copying examples of the required dependency injection in application/Espo/Hooks/Note/Notifications.php

    Comment

    Working...