Announcement

Collapse
No announcement yet.

Copying content of textbox from one entity to second and edit in second

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Copying content of textbox from one entity to second and edit in second

    Advanced Pack

    Hello!


    I have searched the forum but did not find an answer to my issue.

    I have a custom entity with textbox fields. It contains sample texts for different situations to use.
    I tried to get the textbox field with "foreign field" in the second custom entity, which works fine.

    But here the problem:
    I have to edit the content of the textbox in the second entity. Without changing the content of the sample text in the first entity.

    Is there a way to copy the content of the textbox in entity 1 to an empty textbox in entity 2, in order to be able to edit this text in entity 2?

    Thank you for your help!

  • #2
    Hi Gustav,
    The 'Foreign' type field just shows the field value of its parent entity. This field is 'read-only' type so you cannot edit it. For your purpose, you need to create a custom text type field for the second entity and:
    - utilize Workflow to push the entity 1 text field data to entity 2 text field.
    or
    - utilize Formula to fetch the entity 1 text field data to entity 2 text field.

    The way of automation you will choose should depend on logic you are trying to achieve.

    Comment


    • #3
      Hello,

      I think you have to use the formula for this, because the foreign field will not stored in the database but will be fetched from the origin entity every time you fetch the second entity.

      Useful links:



      Try this function:
      https://docs.espocrm.com/administrat...ygetlinkcolumn

      CEO of Eblasoft
      EspoCRM Expert since 2014
      Full Stack Web Developer since 2008
      Creator of Numerous Successful Extensions & Projects​

      Comment


      • emillod
        emillod commented
        Editing a comment
        I'm not sure why, but i prefer hooks

      • eymen-elkum
        eymen-elkum commented
        Editing a comment
        As a developer I agree with you, but clients will not!

    • #4
      Thank you both for your quick reply!

      I am trying to setup the function Eymen is referring to:

      Here the original text of github/formula:

      entity\getLinkColumn


      entity\getLinkColumn(LINK, ID, COLUMN)

      Fetches a relationship column value (since 5.7.1).

      Example:

      entity\getLinkColumn('targetLists', 'TARGET_LIST_ID', 'optedOut')


      My setup, which does not work:

      Entity 1: Textbaustein
      field (textbox) to be copied: massnahme

      Entity 2: BSBFestgestellteGefaehrdung
      field (textbox) to be pasted to: trialfield


      Formula in entity 2 BSBFestgestellteGefaehrdung

      trialfield = entity\getLinkColumn('textbaustein.massnahme', 'TARGET_LIST_ID', 'optedOut');

      Is the formula in entity 2 or should it be in entity 1?
      What do I have to fill in (LINK, ID, COLUMN).

      Sorry, but I am a beginner and have studied "Terms and Namig" several times, still I dont check it...

      Thank you for guiding me!

      Comment


      • #5
        To be honest I am as a developer rarely to use formula, I have made another quick look and found notice said that we can directly access the attributes of linked entities

        https://docs.espocrm.com/administrat...la/#attributes
        "It's possible to access attributes of related entities with the following format linkName.attributeName."

        So, I think you can easily write this:

        trialfield = textbaustein.massnahme;

        NOTE: be so careful for names:
        - is it trialfield or not trialFields
        - textbaustein or textBaustein, this must be the link name and not the entity name in some cases they are the same with first letter small
        CEO of Eblasoft
        EspoCRM Expert since 2014
        Full Stack Web Developer since 2008
        Creator of Numerous Successful Extensions & Projects​

        Comment


        • #6
          Hello Eymen!

          Thank you, it works - for a moment I was really happy - but it does not really work!

          The content of textbaustein.massnahme is fetched into the trialfield in the moment of safing the record.
          Then you can edit the field trialfield.

          But in the moment of safing the edited content, you get the original text of textbaustein.massnahme without changes again. So editing does not work.

          Is there a workaround to safe the edited field content?

          Thank you!

          Comment


          • #7
            I am sorry, I forgot about the origin case, to prevent this from happened you will make this conditionally, try this:

            HTML Code:
            ifThen( !trialfield, trialfield = textbaustein.massnahme);
            CEO of Eblasoft
            EspoCRM Expert since 2014
            Full Stack Web Developer since 2008
            Creator of Numerous Successful Extensions & Projects​

            Comment


            • #8
              Hello Eymen!

              It works perfectly! This is a milestone to my little project! Thank you so much!

              Best regards and have a great day

              Comment


              • #9
                That a cool idea. By the way, you might like to use the Auto Complete (Option) feature too.



                Basically when you edit an blank field it will show up all your Options, I mostly use it for Account's Title and Task

                Comment


                • gustavgraz
                  gustavgraz commented
                  Editing a comment
                  Hi Espcrm: This is a very nice feature, in the meanwhile I already use it! Thank you for pointing that out!

              • #10
                Hi, I am having the same case:

                Entity one has a tax field, from which I would like to hand over the value to entity two, so I wrote this formula:

                Code:
                taxFieldEntityTwo=linkEntityOne.taxFieldEntityOne;
                but it does not work. The entities are connected by n:n relationship.
                Any hint, what I am getting wong?

                Comment

                Working...
                X