No announcement yet.

PDFTemplate - Parent scope

  • Filter
  • Time
  • Show
Clear All
new posts

  • PDFTemplate - Parent scope

    Not sure if I'm using this right, but this code should be able to give me information on the parent entity?


    {{#each contacts}} {{../name}} {{/each}}
    I'm testing this on Task, with the Parent: Contact. Unfortunately all it giving me the Task name itself (twice).

    It should be giving me the Parent (Contact) Name... and if it can do Parent name. Anyone use this formula or know how to get it to work?

    Tested it on the demo but that doesn't seem to work, 3 sample handlebar I used in <code> view; all came out blank.

    {{#each contacts}}
    {{#each task}}
    {{#each tasks}}
    Last edited by espcrm; 09-20-2021, 08:37 AM.

  • #2
    Meeting, Task, Call have parentId and parentType out-of-box (belongTo i think)

    in template, you can have :
    in meeting, you can "each" Users, Leads, Contacts (invitee) in a loop

    {{#each contacts}} {{name}} {{/each}}


    • #3
      Thank item, I know you can use parentName, which is easy but using that code I wanted to get other thing, for example:


      If I can get the code:

      {{#each parent}}

      to work then it mean I can also do thing like:
      {{#each parent}}

      I'm using the example to test if it work for me but it doesn't so I'm not sure which part I'm doing it wrong or if it bug or example is given wrong.


      • #4

        no luck.. parent field is special field (2 field) .. so no possibility to have other field from parent in Pdf

        with my code on other post, you can do it.
        or maybe another solution :
        if your Parent field have "always" same EntityType .. so you can create a relation
        and on hook or formula :

        myAccountId = parentId.

        so you can have all field from AccountId

        But, i don't understand, why you try "each" .. parent is belongTo (1 meeting have 1 parent )


        • #5
          Originally posted by item View Post
          But, i don't understand, why you try "each" .. parent is belongTo (1 meeting have 1 parent )
          Will give the code (grandchild) a try to see if can adopt to this also.

          As for the each, I'm just following the example code here:

          As for usage, I wanted to use Parent because Task parent can change so I just create a single template and get information I need, rather than maintaining 5 Task templates.

          Account <= Task
          Contact <= Task
          (Custom Entity) <= Task
          Properties <= Task

          So can use:
          {{#each parent}}

          instead of having to (example only, I know the code is wrong!):
          Template 1:

          Template 2:

          Template 3, 4....


          • #6
            On Custom/service/Task

            PHP Code:
            namespace Espo\Custom\Services;


            Task extends \Espo\Modules\Crm\Services\Task
            protected function 
            parentData(Entity $entity)
            $em $this->getEntityManager();
            $taskId $entity->id;
            $parentId $entity->get('parentId');
            $parentType $entity->get('parentType');

            $parentEntity $em->getEntity($parentType$parentId);

            //$GLOBALS['log']->warning( json_encode(get_object_vars( $parentEntity->getValueMap() ), true) );

            $entity->set('parentEntity'json_decode(json_encode(get_object_vars$parentEntity->getValueMap() ), true) ) );
            public function 
            loadAdditionalFields(Entity $entity)

            public function 
            loadAdditionalFieldsForPdf(Entity $entity)

            on entityDefs/Task

            PHP Code:
            "parentEntity": {

            And on pdf :



            you can reach all attributes

            It's certainly not perfect but work

            Evidement, need clearCache and Rebuild
            Last edited by item; 09-22-2021, 11:09 AM.


            • #7
              Maybe a feature request to Yuri

              if entity have parentId and parentType
              new field parentEntity

              then parentAttributes in parentEntity for all..

              i think Yuri can do it out-of-box with no long work for all entity
              Last edited by item; 09-22-2021, 11:03 AM.