Formula entity\sumRelated -> Filter?
Collapse
X
-
Great. I suggest to put this on manual.... Another great feature of advanced package. Helps a lot. -
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:
-
-
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/
Is it possible to implement this?Leave a comment:
-
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:
-
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);
into
public function afterSave(Entity $entity, array $options = array()) { parent::afterSave($entity, $options);Leave a comment:
-
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:
-
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:
-
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') ); } }
Leave a comment:
-
Leave a comment:
-
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)
Tags: None
Leave a comment: