Formula entity\sumRelated -> Filter?

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rodrigocoelho
    replied
    Great. I suggest to put this on manual.... Another great feature of advanced package. Helps a lot.

    Leave a comment:


  • yuri
    replied
    It's possible to achieve w/o development using Reports feature. Create Report Filter (at administration).

    Use:

    entity\sumRelated('opportunities', 'amountConverted', 'reportFilter5c41a0a396f66725d');

    where 5c41a0a396f66725d is ID of Report Filter record you can obtain from a url.

    Leave a comment:


  • rodrigocoelho
    replied
    Originally posted by rodrigocoelho

    No way. This could be easier for whom is not a programmer. Why not having filter as an Attribute condition, like "fieldx == 1"

    Is it possible to implement this?
    Got it working, but it is really not easy. At least for who is not a programmer.

    Leave a comment:


  • rodrigocoelho
    replied
    Originally posted by tanya
    custom/Espo/Custom/SelectManagers/[YourEntityToBeFiltered].php and change the namespace to namespace Espo\Custom\SelectManagers;
    for the last better to create a hook https://www.espocrm.com/documentatio...lopment/hooks/
    No way. This could be easier for whom is not a programmer. Why not having filter as an Attribute condition, like "fieldx == 1"

    Is it possible to implement this?

    Leave a comment:


  • tanya
    replied
    custom/Espo/Custom/SelectManagers/[YourEntityToBeFiltered].php and change the namespace to namespace Espo\Custom\SelectManagers;
    for the last better to create a hook https://www.espocrm.com/documentatio...lopment/hooks/

    Leave a comment:


  • komplete22
    replied
    for anyone who may concern the same issue, this is the final hook for calculating fields from a child to a parent:

    PHP Code:
      $taetigkeiten = $entity->get('taetigkeiten');
     $gesamtdauer = 0;
      foreach ($taetigkeiten as $t)  {  
      $dauer = $t->get('dauer');  
      $gesamtdauer = $gesamtdauer + $dauer;
     }
      $entity->set('gesamtdauer',$gesamtdauer); 
    
    put this into custom\repositories\CaseObj.php
    into

    public function afterSave(Entity $entity, array $options = array()) { parent::afterSave($entity, $options);

    Leave a comment:


  • komplete22
    replied
    it seems like it counts every child related records into the sum...
    and not only the ones who are child from the parent record...

    maybe it would be better to implement this with a hook and a afterSave function....
    but I have no idea how I can write a method which gets all child records and iterate through them suming a field together into the parent record... maybe someone can help me here?

    Leave a comment:


  • komplete22
    replied
    and is there a way to debug the formula?

    I always get 3,2 as an result for my formula:

    gesamtdauer = entity\sumRelated('taetigkeiten','Dauer', 'Verrechenbar')

    even though I add more taetigkeiten to the parent datarecord... the number 3,2 does not change in any way.

    Leave a comment:


  • komplete22
    replied
    okay thanks, so a new file Taetigkeit.php under espo\custom\selectmanagers\

    with

    PHP Code:
       namespace Espo\Modules\Crm\SelectManagers;  
    
    class Taetigkeit extends \Espo\Core\SelectManagers\Base {    
    
     protected function filterVerrechenbar(&$result)
        {         $result['whereClause'][] = array(  
              'verrechenbar' => array('true')         );
        }  } 
    
    is fine? verrechenbar is a boolean field...

    Leave a comment:


  • yuri
    replied
    Hi,

    Filter won is defined here https://github.com/espocrm/espocrm/b...tunity.php#L41

    Leave a comment:


  • komplete22
    started a topic Formula entity\sumRelated -> Filter?

    Formula entity\sumRelated -> Filter?

    Hi,

    in documentation there is a example for entity\sumRelated function in formula:

    entity\sumRelated(LINK, FIELD, [FILTER]) Sums related records by a specified FIELD with an optional FILTER. (since version 5.2.6)

    Example:

    entity\sumRelated('opportunities', 'amountConverted', 'won')

    but on which field is 'won'? .. I mean... how can I give a field to the filter like "myfield=true" (boolean)
Working...