build dynamic aggregate model

I’m trying to build aggregate models dynamically, and I’m getting a VF remoting exception:
Field must be grouped or aggregated: Preliminary_AVR__c

As you can see in the code below, I’m trying to group on the Preliminary_AVR__c field, but apparently not?

Here’s the setup of the code:

getPrelimAVR: function(s,e,l,previous){<br> var model = new mm();<br> model.objectName = 'Patient_Case__c';<br> model.id = (previous ? 'Prev_': '') + 'PrelimAVR';<br> model.type = 'aggregate';<br> model.isAggregate = true;<br> model.fields = [<br> {id: 'Id', name: 'records', function:'COUNT_DISTINCT'},<br> {id: 'Preliminary_AVR__c', name: 'grouping', groupable: true}<br> ];<br> model.groupByFields = [<br> {id: 'Preliminary_AVR__c', name: 'grouping'}<br> ];<br> model.conditions = [<br> {type: 'fieldvalue', field: 'HasCompleteAppointment__c', operator: '!=', value: '0', encloseValueInQuotes: false},<br> {type: 'fieldvalue', field: 'First_Complete_Interaction_Date__c', operator: 'gte', name: 'Start', value: s, inactive: !s, encloseValueInQuotes: false},<br> {type: 'fieldvalue', field: 'First_Complete_Interaction_Date__c', operator: 'lte', name: 'End', value: e, inactive: !e, encloseValueInQuotes: false},<br> {<br> type: 'multiple', field: 'Center_Location__c', operator: 'in', values: location || [''], name: 'Location',<br> inactive: !(location &amp;&amp; location[0]), encloseValueInQuotes: true, encloseValueInParens: true<br> }<br> ];<br> return model.initialize();<br> }


What am I missing?

Matt is there a specific reason why you are not using model aggregation out the box?

Looks like I just needed to include the groupByMethod:

model.groupByMethod = ‘simple’;

OK well glad you got that sorted out.  I thought you had perhaps tried this in mobile builder.  There is also a solution there by building it out in desktop and copying the XML into mobile builder and hey presto your’e done.

Happy Skuiding