Conditional Rendering based on Sum in Aggregate Model?

I am really digging all of the new conditional rendering options. 

Wondering if it is possible to render a component based on the sum of a field in an aggregate model?

ie) Render if the total hours from all the timecards in this aggregate model < 10

This absolutely works. But it takes a little hacking around.

Set up the aggregate model as you always would.

Then set up the render condition and choose the field you built the aggregation on. However you need to actually specify the aggregate field alias in this section, so we have to go to the XML and make a few tweaks.

  1. When I was testing, for some reason, adding the aggregate field to my render condition gave the aggregate model 2 lines in the aggregatation section. I had to delete one in the XML. Maybe that won’t happen to you - but just in case…

  1. Then I changed the model name in the render condition statemement. I found the component where I had conditional rendering. Found the Field property and replaced the field name with the alias name from my aggregate model.

That will get you basic field rendering. But there is an extra trick.

When you save your timecards, you want the rendering to take place immediately - not waiting for a page reload. To do this add a model action to your basic timecards model - such that when they are saved, the aggregate model is requeried. This will update the aggregations and the rendering…


Wooo!!! Thank you!

Another question - can I access custom fields on the running user attribute that are not listed in the dropdown? or can I edit the xml to grab another value from someplace else? Either on the user object or really any object. 

I will create a formula field that shows the number of hours that should be tracked by now based on the day of the week. The render condition will say “render it this way if the aggregate hours are greater than or equal to this formula field value”, and another way if less than. 

Does that make sense? 

That’s 3 times in one week where conditional rendering based on the comparison of two fields has been asked for.  We do not currently support adding merge fields into the value property of the condition builder.  We’ve been hacking around some Javascript that might allow you to do this,  but haven’t gotten it right yet. 

When it rains it pours.