Error in return Timeseries from method


#1

I have this method for a type ServicePoint:

/*
Starting from a service point evaluate a metric on his LEVEL-D facility (parentFacility of facility)
to get the aggregate metric values of the servicePoints for that facility.
*/
function evalFacilityLevelD(obj, spec, metric, name) {

    var servicePoint = ServicePoint.fetch({
        filter: Filter.eq('id', obj),
        include: 'id,facility,facility.parentFacility'
      }).at('objs[0]');

    return Facility.evalMetrics({
        filter: Filter.eq('id', servicePoint.facility.parentFacility),
        expressions: [name],
        start: spec.start,
        end: spec.end,
        interval: spec.interval
        });
}

but when i try to call it it gives me the error:
`

Unable to convert JavaScript object to expected type Timeseries

If i try to change

return Facility.evalMetrics({
        filter: Filter.eq('id', servicePoint.facility.parentFacility),
        expressions: [name],
        start: spec.start,
        end: spec.end,
        interval: spec.interval
        });

into

return Facility.rollupMetric({
    filter: Filter.eq('id', servicePoint.facility.parentFacility),
    expressions: [name],
    start: spec.start,
    end: spec.end,
    interval: spec.interval,
    rollupFunc: 'SUM'
    });

everything works but this is not the optimal solution :slight_smile:

Thanks!
Aldo


#2

You have this error because evalFacilityLevelD have to return one instance of Timeseries but what evalMetrics return is EvalMetricsResult type.
Use evalMetric instead like this:

return Facility.evalMetric({
    id: servicePoint.facility.parentFacility.id,
    expression: name,
    start: spec.start,
    end: spec.end,
    interval: spec.interval
});

#3

thanks Bachir, this is what i was looking for!