Announcement

Collapse
No announcement yet.

concatenate array (enum) and string

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

  • concatenate array (enum) and string

    Is it possible to use the formula string\concatenate to join multi enum and text field values?

  • #2
    Doubt it if you asking this question (I assume you must have tried). Only thing I can think of (have not test) is to cheat. You know how Print2PDF can use {each} {/each}, perhaps it might work with Formula as well?

    Comment


    • #3
      look https://docs.espocrm.com/administration/formula/#list , while, and concat

      Comment


      • #4
        Hi,
        item, I already considered that, but what would be the values? list(VALUE-1, ... VALUE-N), will I use some Id`s, from where do I achieve them, will I have to use the actual values of all the enum values as string??

        The following while condition I don`t understand.

        Code:
        $source = list(0, 1, 2);
        $target = list();
        $i = 0;
        while($i < array\length($source), $target = array\push( $target, array\at($source, $i) );
        $i = $i + 1; );
        The documentation is very difficult to understand, for whom never did that before. Lot of guessing.

        Comment


        • #5
          Using formula requires some programming skills, except when the logic is very simple.

          'list' function instantiates an array by given values.

          There's no join function at the moment. I suggest adding a custom function. See https://docs.espocrm.com/development...on-in-formula/


          custom/Espo/Custom/Core/Formula/Functions/MyGroup/MyJoinType.php

          PHP Code:
          <?php
          namespace Espo\Custom\Core\Formula\Functions\MyGroup;

          class 
          MyJoinType extends \Espo\Core\Formula\Functions\Base
          {
              public function 
          process(\StdClass $item)
              {
                  
          $args $this->fetchArguments($item);

                  return 
          implode($args[1], $args[0]);
              }
          }

          `custom/Espo/Custom/Resources/metadata/app/formula.json`

          Code:
          {
              "functionClassNameMap": {
                  "my\\join": "Espo\\Custom\\Core\\Formula\\Functions\\MyGroup\\MyJoinType"
              }
          }
          Then use:
          Code:
          $joinedString = my\join($array, ', ');
          Last edited by yuri; 02-12-2021, 10:17 AM.

          Comment


          • #6
            yuri , thank you, I will try, but I think it will be beyond my skills in coding (if there are some at all)

            Comment


            • #7
              I saw this issue, I think yuri made it possible in v6.2?
              Formula: array\join function #1917

              Comment


              • #8
                yuri and esforim the new formula in 6.1.3 works perfectly. Thank you.

                Comment


                • esforim
                  esforim commented
                  Editing a comment
                  That good to hear, did you manually patched that code in? I initially thought it was v6.2 but looking at it again it listed as v6.1.3 instead

                  In the end how does formula look in the end? One that is a "live working example".

              • #9
                esforim , yes it has been implemented in 6.1.3 and my formula outputs all values from an enum field this way:

                my target field = legendeTechnik, is a plain textfield, that should show all values of an existing enum field named "technik" in one comma separated field.

                Formula:

                Code:
                legendeTechnik=array\join(technik, ', ');
                Be aware, that after the comma itself there is a space to line up the values with a space after the comma. The result looks like this:

                technik1, technik2, technik3, ....

                Further on you may e.g. concatenate this new text field with other fields as usual.

                Comment


                • #10
                  Mr shalmaxb looking at the date wow! 2 and half year later I'm finally playing to your level.

                  How do you create new lines for each of the technik1, technik2, technik3, .... result?

                  For example, right now it showing as technik1, technik2, technik3, ....

                  I want it as

                  technik1
                  technik2
                  technik3, ....
                  Last edited by esforim; 06-29-2023, 09:05 AM.

                  Comment


                  • esforim
                    esforim commented
                    Editing a comment
                    Update; and thinking on my feet, I got this. So here is the solution:

                    output\printLine(array\join($nameArray, '\n'))

                  • shalmaxb
                    shalmaxb commented
                    Editing a comment
                    that`s right '\n' for line break. And in case you need to print this in PDF, here is the solution to escape: https://forum.espocrm.com/forum/gene...4187#post94187

                • #11
                  shalmaxb While we are on this topic, do you ever have to do something like this? I don't know how your technik field data is structured.

                  Anyone know what Regular Expression type does EspoCRM use? I use regex101.com to test and some regex work and some doesn't. It obviously I'm using the wrong setting so it to be expected. For example: Using this regex in RegEx101 work fine, but if I use it in EspoCRM I don't get a match. Need to know which setting I should be


                  It because of these array result that I need to separated them into their "category". Currently I'm​ making everyone in the same group so it doesn't work too well, instead of separate them into their group such as "Buyer" and "Seller".

                  Now it just
                  technik1
                  technik2
                  technik3

                  Instead of something like
                  Buyer:
                  technik ​​

                  Seller:
                  technik2
                  technik3

                  Do you play regex often?
                  Last edited by esforim; 06-29-2023, 09:18 AM.

                  Comment


                  • #12
                    I never worked with regex so far, because I did not need. And honestly it is quite a mystery for me.

                    Comment


                    • esforim
                      esforim commented
                      Editing a comment
                      Hmm maybe one day. Hopefully by then I'm more fluent and I can help you instead!
                  Working...
                  X