Announcement

Collapse
No announcement yet.

PDFTemplate - Parent scope

Collapse
X
 
  • 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?

    Documents: https://docs.espocrm.com/user-guide/...#each-iterator

    Code:
    {{#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.

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

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

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


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

    Comment


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

      {{parent.description}}
      {{parent.address}}

      If I can get the code:

      {{#each parent}}
      {{../name}}
      {{/each}}

      to work then it mean I can also do thing like:
      {{#each parent}}
      {{../name}}
      {{../description}}
      {{../phone}}
      {{/each}}

      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.

      Comment


      • #4
        Hello,

        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 )

        Comment


        • #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: https://docs.espocrm.com/user-guide/...#each-iterator

          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}}
          {{../name}}
          {{/each}}

          instead of having to (example only, I know the code is wrong!):
          Template 1:
          {{account.task.name}}
          {{account.task.description}}

          Template 2:
          {{contact.task.name}}
          {{contact.task.description}}

          Template 3, 4....

          Comment


          • #6
            On Custom/service/Task


            PHP Code:
            <?php
            namespace Espo\Custom\Services;

            use 
            Espo\ORM\{
            Entity,
            EntityManager,
            ServiceFactory,
            };

            class 
            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)
            {
            parent::loadAdditionalFields($entity);
            $this->parentData($entity);
            }

            public function 
            loadAdditionalFieldsForPdf(Entity $entity)
            {
            $this->loadAdditionalFields($entity);

            }
            }
            on entityDefs/Task

            PHP Code:
            ,
            "parentEntity": {
            "type""jsonObject",
            "notStorable"true,
            "layoutDetailDisabled"true,
            "layoutFiltersDisabled"true,
            "layoutListDisabled"true,
            "reportDisabled"true


            And on pdf :

            {{parentEntity.[id]}}

            {{parentEntity.[name]}}

            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.

            Comment


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

              Comment

              Working...
              X