Announcement

Collapse
No announcement yet.

custom formula refresh problem

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

  • custom formula refresh problem

    i created a custom formula for test that returns the sum if 2 numbers,
    it works fine , but i need to refrech the page manualy after each update to have the new value
    PHP Code:
    <?php

    namespace Espo\Custom\FormulaFunctions\Math;

    use 
    Espo\Core\Formula\Functions\BaseFunction;
    use 
    Espo\Core\Formula\ArgumentList;

    class 
    SumTwoNumbers extends BaseFunction
    {
        public function 
    process(ArgumentList $args)
        {
            
    // Check if exactly two arguments are provided
            
    if (count($args) !== 2) {
                throw new 
    \Error('SumTwoNumbers function expects exactly two arguments.');
            }

            
    // Evaluate the arguments to get the numbers
            
    $number1 $this->evaluate($args[0]);
            
    $number2 $this->evaluate($args[1]);

            
    // Return the sum of the two numbers
            
    return $number1 $number2;
        }
    }

  • #2
    The code you provided is just a function. It has nothing to do with why your change is not displayed. More relevant info is needed. Your formula script.

    Comment


    • zerosix
      zerosix commented
      Editing a comment
      <?php

      namespace Espo\Custom\FormulaFunctions\Math;

      use Espo\Core\Formula\Functions\BaseFunction;
      use Espo\Core\Formula\ArgumentList;

      class SumTwoNumbers extends BaseFunction
      {
      public function process(ArgumentList $args)
      {
      // Check if exactly two arguments are provided
      if (count($args) !== 2) {
      throw new \Error('SumTwoNumbers function expects exactly two arguments.');
      }

      // Evaluate the arguments to get the numbers
      $number1 = $this->evaluate($args[0]);
      $number2 = $this->evaluate($args[1]);

      // Return the sum of the two numbers
      return $number1 + $number2;
      }
      }

  • #3
    PHP Code:
    <?php

    namespace Espo\Custom\FormulaFunctions\Math;

    use 
    Espo\Core\Formula\Functions\BaseFunction;
    use 
    Espo\Core\Formula\ArgumentList;

    class 
    SumTwoNumbers extends BaseFunction
    {
        public function 
    process(ArgumentList $args)
        {
            
    // Check if exactly two arguments are provided
            
    if (count($args) !== 2) {
                throw new 
    \Error('SumTwoNumbers function expects exactly two arguments.');
            }

            
    // Evaluate the arguments to get the numbers
            
    $number1 $this->evaluate($args[0]);
            
    $number2 $this->evaluate($args[1]);

            
    // Return the sum of the two numbers
            
    return $number1 $number2;
        }
    }
    PHP Code:
    {
        
    "functionClassNameMap": {
            
    "SumTwoNumbers""\\Espo\\Custom\\FormulaFunctions\\Math\\SumTwoNumbers"
        "functionList"
    : [
            {
                
    "name""SumTwoNumbers",
                
    "insertText""SumTwoNumbers(NUMBER1, NUMBER2)"
            
    }
        ]
    }
    ​ 
    Last edited by zerosix; 03-17-2024, 12:03 AM.

    Comment


    • #4
      Hi zerosix

      This is what your the code should be like

      PHP Code:
      {
          
      "functionClassNameMap": {
              
      "sumTwoNumbers""Espo\\Custom\\FormulaFunctions\\Math\\SumTwoNumbers"
          
      },
          
      "functionList": [
              
      "__APPEND__",
              {
                  
      "name""sumTwoNumbers",
                  
      "insertText""sumTwoNumbers(NUMBER1, NUMBER2)"
              
      }
          ]
      }
      ​ 

      Then in formula just use sumTwoNumbers(2,3)

      Comment


      • zerosix
        zerosix commented
        Editing a comment
        thank you rabii, still having the problem

    • #5
      My first reply is still relevant. It does not matter what function you call. It does matter how you use it.

      Comment


      • zerosix
        zerosix commented
        Editing a comment
        i am using it in forrmula editor
        result= = SumTwoNumbers(1, 2);

      • PMUM
        PMUM commented
        Editing a comment
        If you are in Formula Sandbox, I hope your formula looks more like this:

        $result = SumTwoNumbers(1, 2);
        output\printLine($result);
    Working...
    X