No announcement yet.

Stuck showing the value of a field of another entity

  • Filter
  • Time
  • Show
Clear All
new posts

  • Stuck showing the value of a field of another entity


    I have one entity and there I want to show the value of a field from another entity (no problem, when it is read-only). The both entities are linked by relationships. I tried with formula:

    where artCollectionWorks is the entity from where I want the field verkaufspreisbrutto (currency).

    I also tried:

    where artCollectionWorkss.verkaufspreisbrutto is the relationship.field.

    I tried also creating a foreign field in the new entity, but it does not show a link to that respective field (verkaufspreisbrutto)

    Is that, what I want possible? Where is my mistake, if so? Any heöp appreciated

  • #2
    Foreign field and Formula don't support fetching data this way for link-multiple connection. You need to write Hook for this purpose


    • #3
      Thank you for the answer, I already guessed (feared) that. I do not understand at all, how the hook in espoCRM works. I understand, that I will have to create that file in the custom folder.
      From my example, to show a field from one entity in another, where in my entity(ies) this appears and with which configuration? Where do I put the file? In a folder with the name of the source entity or target entity? What happens next? Where do I see the result and how will I have to configure that?
      Unfortunately, the documentation is not understandable, if you have done this never before. Perhaps someone could help me a bit with my own example.

      Will I have to configure anything in the admin account, do I need an API-user? Do I have to create the webhook afterwards in the admin-panel under webhooks?

      so, i have

      - one entity, named "artCollectionWorks" with a field "verkaufspreisbrutto", a currency field
      - another entity, named "versand", where I want to show the former mentioned field "verkaufspreisbrutto"
      - these entities are linked by relationship/multiple-link

      I guess, I will have to tell the hook script, from which entity which field I want to show, in which entity which field. Where does this field appear? Do I have to provide the field before in the target entity? What format does it have to have?

      Here is the example script from the documentation and my questions:

      Click image for larger version  Name:	hook.jpg Views:	0 Size:	46.7 KB ID:	63526
      I apologize for the amount, but that`s the way it goes, when you never have done this before.
      And thank you in advance.


      • #4
        i respond to some :
        when you create new Entity => custom/Espo/custom/Entities/ ....
        here you can see name of Entity .. look in the file.

        when you create a hook :
        create a file in custom/Espo/Custom/Hook/YourEntityName/.... you can choose a simplyName like : MyEntity.php
        MyEntity must be the name of the class in these file.
        In your sample : AccountName.php => class AccountName..

        i use sample : entity = Blabla : BlablaHooks.php => class BlablaHooks
        You must Adapt namespace : Espo\Custom\Hooks\Blabla. => path to directory of the file.
        use Espo\ORM\Entity => don't touch

        beforeSave(Entity $entity, array $options = []). ... don't touch .. must be so..

        In my sample :

        $entity->set('blablaField', 'myTouch') => $entity = Blabla entity...
        blablaField receive 'myTouch' value..

        you only work at this sample on "Blabla" entity ... if you will need work for related entity .. is little more complexe

        Please : write me :
        sample : Account -> Contact Account have many2many Contact. or Account have one2many Case.
        How his your relation . .print-screen of the main entity in entity relation manager in admin section ?

        I think is a little more complex with "currency" field.. i have not investigate but when you add a "currency" field in entity manager, 2 field are created.. it's why i use only float .. it's ok for us...

        And for me : as i see, you write nice in english.. is't for me better give "english name" to all (entity, field) ... so we can more good understand. .. it's just my 2 cent idea

        PS : i can assist you by skype/teams/teamviewer if you will for free.. my english is poor but speak french.
        Last edited by item; 10-13-2020, 08:01 PM.


        • #5
          item , thank you very much for your help. I start to understand so far. I will try to explain better, perhaps there could be some more hints.

          What do I want to achieve? I change the names of the entities to a more general name: source (from where I want the field content) and target (where I want to show the field content from the source. The field, that I want, is price.

          I already have an entity called source (it is a system to administrate artwork like paintings, sculptures and alike).

          The artwork is represented by this entity with many fields, from which one is the price. This is a currency field called price.

          I created another entity to organize transports of art (e.g. sold work to a buyer, transport to an exhibition). This entity bears all data necessary to ask for quotes and organize the paperwork to deliver the work. This I call target.
          I created a relationship many:many between source and target. This way I am able to choose a work from the entity source to show up in the entity target. This works fine.

          For the entity target I need to provide a value of the artwork for base calculation of the insurance, which in most cases is the sales price (which I already have in the source entity/price).
          Therefore I created a currency field in the entity target with the name of price (insurance value), which I would like to fill automatically with the price, which comes from the source entity.

          For that I will have to create a hook.

          As already mentioned in my other post, here the problems begins, but some questions I already could sort out.

          The example script from the documentation I modified in the following way:

          My file: custom/Espo/Custom/Hooks/Lead/InsuranceValue.php

          namespace Espo\Custom\Hooks\Target;
          use Espo\ORM\Entity;
          class InsuranceValue extends \Espo\Core\Hooks\Base
          // from here, I don`t know yet
          public function beforeSave(Entity $entity, array $options = [])
          if ($entity->isNew() && !$entity->get('accountName')) {
          $entity->set('accountName', 'No Account');
          What do I still not understand:

          1. in my case, what do I have to write into the if condition?
          2. how do I "tell" the field price in target entity, from where the value comes and how do I achive this with the field? Doesn`t this field need any command?
          3. How the hook is triggered? Will the field in target entity automatically be filled?
          Last edited by shalmaxb; 10-15-2020, 11:25 AM. Reason: Changed the names for the respective entities to more general as source and target, for better understanding.


          • #6
            i understand more :

            let me brainstorm :

            ArtWorks is unique "Joconde" -> can have manyTransport .. to belgium, to france..(not sell.. so ..another place..and then sell ) but not, you can transport same ArtWorks to X place in same time (or is copy )... one transport -> one price -> one insurance ..
            ArtWorks have a price .. so Transport can foreign to price (not sure with curency but calculedfield to float and it's ok) if one2many !
            You are "lost" because many2many ..

            Account -> contact in espoCRM is many2many but with a special thing : contact.primaryAccount..
            so in database you have :
            account - account_countact - contact .. but in table contact, you have "acount_id" field = primaryAccount.

            I think in your case, you must change many2many to one2many : one Artwork 2 many Transport.
            so you can foreing.. and you can have in all pdf, all field .. Artwork and Transport..
            and in Transport, can make calculated field .. with foreign field price ... no need code.

            You ask code with many2many.. can't possible the result have big ..

            And one more entity : Truck maybe one2many Transport
            and on truck .. you can sum/related(insurance, price)..

            And you say : My file: custom/Espo/Custom/Hooks/Lead/InsuranceValue.php must be custom/Espo/Custom/Hooks/Transport/InsuranceValue.php

            Else the content of file is good but :
            in beforeSave... there is no "relationShip" still..

            Don't whorry to ask me .. fryday

            Last edited by item; 10-14-2020, 08:56 PM.


            • #7
              Just a comments; I think when you write fieldname on forum; I think it is best to write to be be something simple that can be remember. When I read this fieldname I just get lost in the abyss, not sure if other feel the same, "artCollectionWorkss.verkaufspreisbrutto"

              Your actually field name can be anything.

              PS: this thread is good learning.


              • shalmaxb
                shalmaxb commented
                Editing a comment
                Hi, thank you for the hint. I changed the entity names to more general as source and target. Hope that helps to understand.

            • #8
              To realize, what I wanted, I tried another approach, which is quite, what I wanted to achieve. From the post of item I concluded to try other types of relationships and using foreign field. In relationship on-to-one-right I succeded to place this field in the target entity and it shows the value, that I need. So perhaps, this could be the more easier way to show values from one entity into another.
              Nevertheless I really would like to understand the webhook thing.
              Last edited by shalmaxb; 10-15-2020, 11:40 AM.


              • item
                item commented
                Editing a comment
                Hello shalmaxb,

                no, one-to-one right is not the good relationship ... it's strange as relationship, not really understand !
                you must one2many ! you can foreign with this .. or it's easy to have parent field value in many child.