Own Record-List Dashlet with Data of foreign entities

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SebastianZ
    Member
    • Apr 2017
    • 39

    Own Record-List Dashlet with Data of foreign entities

    I created a custom dashlet to shown all opportunities from that belongs to a customer, related to opportunities is in my case an entity called "Projekt". Because a lot of Opportunities belongs to a "Projekt". In the Entity "Projekt" I have an Image that I want to show in my custom daslet, but I don't know how to!

    My Dashlet:

    {
    "view":"views/dashlets/abstract/record-list",
    "aclScope": "Opportunity",
    "entityType": "Opportunity",
    "options": {
    "fields": {
    "title": {
    "type": "varchar",
    "required": true
    },
    "autorefreshInterval": {
    "type": "enumFloat",
    "options": [0, 0.5, 1, 2, 5, 10]
    },
    "displayRecords": {
    "type": "enumInt",
    "options": [3,4,5,10,15,20,30]
    }
    },
    "defaults": {
    "sortBy": "closeDate",
    "asc": true,
    "displayRecords": 5,
    "expandedLayout": {
    "rows": [
    [
    {
    "name":"projekt.bild"
    },
    {
    "name": "name",
    "link": true
    }
    ],
    [
    {
    "name": "stage"
    },
    {
    "name": "amount"
    }
    ]
    ]
    },
    "searchData": {
    "bool": {
    "onlyMy": false
    },
    "primary": "all"
    }
    },
    "layout": [
    {
    "rows": [
    [
    {"name": "title"}
    ],
    [
    {"name": "displayRecords"},
    {"name": "autorefreshInterval"}
    ]
    ]
    }
    ]
    }
    }

    Tried to load the Image in the Custom Opportunity.php

    <?php

    namespace Espo\Custom\Services;

    use \Espo\ORM\Entity;

    class Opportunity extends \Espo\Modules\Crm\Services\Opportunity
    {
    public function loadAdditionalFieldsForList(Entity $entity)
    {
    parent::loadAdditionalFieldsForList($entity);
    $entity->loadLinkMultipleField('contacts');
    $entity->loadLinkMultipleField('projekt','bild');

    }
    }

    What did i missed?
    Last edited by SebastianZ; 05-15-2017, 06:50 AM.
  • SebastianZ
    Member
    • Apr 2017
    • 39

    #2
    Any hint?

    Comment

    • tanya
      Senior Member
      • Jun 2014
      • 4308

      #3
      Hello
      As I think - create notStorable image field for Opportunity. Fill it in loadAdditionalFieldsForList method. And use this field in dashlet

      Comment

      • SebastianZ
        Member
        • Apr 2017
        • 39

        #4
        Hi Tanya,

        if I add an notStorable Image field like this:

        "projektImage": {
        "type": "image",
        "required": false,
        "notStorable": true,
        "readOnly": true
        }

        I get the following error:

        [2017-05-17 14:49:41] Espo.ERROR: API [GET]:/:controller, Params:Array ( [controller] => Opportunity ) , InputData: - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'opportunity.projekt_image_id' in 'field list' [] []
        [2017-05-17 14:49:41] Espo.ERROR: Display Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'opportunity.projekt_image_id' in 'field list', Code: 42S22 URL: /api/v1/Opportunity?maxSize=10&offset=0&sortBy=stage&asc=t rue&where%5B0%5D%5Btype%5D=primary&where%5B0%5D%5B value%5D=open [] []

        As test, I changed the type to text and it worked without problems.

        Comment

        • tanya
          Senior Member
          • Jun 2014
          • 4308

          #5
          Did you rebuild EspoCrm? After rebuilding this column is added. Also fill in service projektImageId field ( = $projekt->get('billId'))

          Comment

          • SebastianZ
            Member
            • Apr 2017
            • 39

            #6
            Rebuild did the trick!
            Now next problem no Images are shown. Is my code for fetching the data right?

            public function loadAdditionalFieldsForList(Entity $entity)
            {
            parent::loadAdditionalFieldsForList($entity);
            $entity->loadLinkMultipleField('contacts');

            $entity->set('projektImage',$entity->get('projekt')->get('bild'));
            $entity->set('projektImageId',$entity->get('projekt')->get('bildId'));

            }

            Comment

            • tanya
              Senior Member
              • Jun 2014
              • 4308

              #7
              Code:
              public function loadAdditionalFieldsForList(Entity $entity)
              {
                  parent::loadAdditionalFieldsForList($entity);
                  $entity->loadLinkMultipleField('contacts');
                  $entity->set('projektImageId',$entity->get('projekt')->get('bildId'));
              }
              is enought

              I checked this code and it works fine. Is this service file read? Do you use in layouts projektImage field?

              Comment

              • SebastianZ
                Member
                • Apr 2017
                • 39

                #8
                ok, its the same problem as described under reports with new uploaded images it works well.

                Thx

                Comment

                Working...