Announcement

Collapse
No announcement yet.

Add new function: Not working.

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

  • Add new function: Not working.

    Hi guy,
    I have tried to add new function Getlastword in string group as below path:
    application/Espo/Core/Formula/Functions/StringGroup/GetlastwordType.php
    code:
    namespace Espo\Core\Formula\Functions\StringGroup;

    use \Espo\Core\Exceptions\Error;

    class getlastword extends \Espo\Core\Formula\Functions\Base
    {
    public function process(\StdClass $item)
    {
    if (!property_exists($item, 'value')) {
    return '';
    }

    if (!is_array($item->value)) {
    throw new Error();
    }

    if (count($item->value) < 1) {
    throw new Error();
    }

    $value = $this->evaluate($item->value);
    $php_pot = strripos($value,' ');
    return substr($value,$php_pot);
    }
    }


    Then I this function to function list as path:
    custom/Espo/Custom/Resources/metadata/app/formula.json

    formular.json file:

    {
    "functionList": [
    {
    "name": "string\\Getlastword",
    "insertText": "string\\Getlastword(String)"
    }
    ]
    }


    But it's not working.Please help if I do wrong.
    Thank you very much.
    Brian.
    Last edited by yuri; 05-30-2018, 08:47 AM.

  • #2
    Wrong class name. And check the case again in example


    GetlastwordType - class name
    getlastword in app/formula file

    Comment


    • #3
      Hi Tanya,
      Now there is only function Getlastword available in choosing listplease see attached file)
      And please also check below code is correct or not since it seem not working.
      namespace Espo\Core\Formula\Functions\StringGroup;

      use \Espo\Core\Exceptions\Error;

      class getlastword extends \Espo\Core\Formula\Functions\Base
      {
      public function process(\StdClass $item)
      {
      if (!property_exists($item, 'value')) {
      return '';
      }

      if (!is_array($item->value)) {
      throw new Error();
      }

      if (count($item->value) < 1) {
      throw new Error();
      }

      $value = $this->evaluate($item->value);
      $php_pot = strripos($value,' ');
      return substr($value,$php_pot);
      }
      }

      Comment


      • #4
        Dear Tanya,
        My customized is working fine now.
        But there is only my customized function.Others was gone.
        Please help to check.
        Thanks

        Comment


        • #5
          try add "__APPEND__" as first item in functionList
          Code:
          {
          "functionList": [
          "__APPEND__",
          {
          "name": "string\\Getlastword",
          "insertText": "string\\Getlastword(String)"
          }
          ]
          }
          and clear the cache

          Comment


          • #6
            Hi Tanya,
            I have already added and clear cache but nothing happen.
            Please check
            {
            "functionList": [
            "__APPEND__",
            {
            "name": "string\\Getlastword",
            "insertText": "string\\Getlastword(String)"
            }
            ]
            }

            Comment


            • #7
              It's working.Maybe after I clear cache my browser is still keep cache or cookie.
              Thanks Tanya

              Comment


              • #8
                I am also having an issue with getting custom functions to list in the workflow functions area. I have added the formula.json to custom/Espo/Custom/Resources/metadata/app/ folder and the I have tried both the code mentioned above and the code found on the github tutorial "Defining new functions for Forumla" The main difference between the two is the github is missing the closing "]" and the code above has a closing "]". I have also created a file called ShiftType.php in the application/Espo/Core/forumla/Functions/ArrayGroup/ Folder with the following code:
                <?php
                namespace Espo\Core\Formula\Functions\ArrayGroup;

                use \Espo\Core\Exceptions\Error;

                class ShiftType extends \Espo\Core\Formula\Functions\Base
                {
                public function process(\StdClass $item)
                {
                return $item[0];
                }
                }

                Am I missing something here?

                Comment


                • #9
                  as you can see $item is object, but you use it as array

                  use this formula as example

                  Comment


                  • #10
                    That wasn't necessarily my issue, i can't get the function to add the the list of functions that are already there.

                    Comment


                    • #11
                      attach your custom/Espo/Custom/Resources/metadata/app/formula.json file, please.

                      Comment


                      • #12
                        Here are the two ways I have tried to make the forumla.json file located in: custom/Espo/Custom/Resources/metadata/app/formula.json
                        I have tried it two different ways, the way recommended in the tutorial,
                        {
                        "functionList": [
                        {
                        "name": "array\\shift",
                        "insertText": "array\\shift(ARRAY)"
                        }
                        ]
                        }

                        -- And The way you recommended above:

                        {
                        "functionList": [
                        "__APPEND__",
                        {
                        "name": "array\\shift",
                        "insertText": "array\\shift(ARRAY)"
                        }
                        ]
                        }

                        Comment


                        • #13
                          It is working now, I used this for my formula.php file:
                          Code:
                          {
                          "functionList": [
                          "__APPEND__",
                          {
                          "name": "array\\shift",
                          "insertText": "array\\shift(ARRAY)"
                          }
                          ]
                          }
                          not sure what changed, but thank you for your help I really appreciate you taking the time to answer my questions!

                          Comment

                          Working...
                          X