build dynamic aggregate model

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

What am I missing?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 2 years ago

  • 1
Photo of Gregg Baxter

Gregg Baxter, Official Rep

  • 3,080 Points 3k badge 2x thumb
Matt is there a specific reason why you are not using model aggregation out the box?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Looks like I just needed to include the groupByMethod:

model.groupByMethod = 'simple';
Photo of Gregg Baxter

Gregg Baxter, Official Rep

  • 3,080 Points 3k badge 2x thumb
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