AnsweredAssumed Answered

Add a filter when rolling up related record calculated fields

Question asked by Steve Cox on Dec 3, 2015

Hi,

 

In a more general followup to this question:

 

I want to use maxRelatedDate in SugarLogic but only with a subset of records.

 

It looks like all related record calculations - whether dates, integers etc - will calculate across all the related records (max, sum, etc).

 

I want to only process those related records with a specific filter. For example, when rolling up data from meetings related to an account, I only want to consider those meetings marked as 'held' - I don't want to consider ones missed or those that are scheduled in the future.

 

One solution would be to create a calculated field in the meeting record that is set to the same value as the field you want to roll up - but with a condition based on the filter. So, for example, this field could be called 'held_date' and set to the start_start date if the meeting status is 'held. Otherwise it's set to null.

 

Then the account 'most_recent_meeting' calculated field could be set as the maxRelatedDate of the meetings' 'held_date' rather than 'start_date'.

 

The problem here is that calculated fields can't be based on other calculated fields. There is a work around based on the order in which these are created but I'm concerned that this may not be valid for v7 or may be blocked in the future: How To - Bring the latest calendar date from a related module into a record in SugarCRM | EnableCRM (in reference to the calc fields based on other calc fields - the roll-up of dates detailed in this post is redundant now the relatedDates functions are available).

 

So, I'm thinking that I can update my 'held-date' field in a meeting record with a before_save logic hook call - as I believe that this logic hook is called before calculated fields are generated. But can anyone confirm this is the case?

 

Thanks

Outcomes