Conditional Calc Fields Throwing Errors


#1

I’m currently adding two calc fields to SummaryBill that rely on two existing fields, so it’s now defined as the following:

@ts(treatment='integral')
consumption: ExactDimension

@ts(treatment='rate')
peakDemand: ExactDimension

consumption_flip: ExactDimension calc "parent.resource.id == 'xyz' ? peakDemand : consumption"

peakDemand_flip: ExactDimension calc "parent.resource.id == 'xyz' ? null : peakDemand"

I can fetch specific SummaryBills by filtering and get no error (and the calc fields return as expected); however, if I do a SummaryBill.fetch(), I get the following error:

Error: Invalid Dimension: 'value' field in Obj<ExactDimension> [,]↵ at new C3.client.ActionError

Is there anything obviously wrong with these calc fields? If not, how can I further debug to find offending records that are causing this?


#2

This allows me to fetch the SummarBills, but these fields end up always being empty…?

consumption_flip: ExactDimension calc "parent.resource.id != 'xyz' ? {value: consumption.value, unit: consumption.unit} : {value: peakDemand.value, unit: peakDemand.unit}"

peakDemand_flip: ExactDimension calc "parent.resource.id != 'xyz' ? {value: peakDemand.value, unit: peakDemand.unit} : null"

#3

@sean.summers Where is this happening? Is it something that can be reproduced locally?


#4

@trothwein This is happening in a QA environment. I cannot reproduce locally, which leads me to believe there is an offending SummaryBill record causing the issue.


#5

What’s also odd is that

SummaryBill.evaluate({projection: "unique(parent.resource.id)"})

Returns only ‘xyz’, when I know for a fact I can fetch other SummaryBills where parent.resource.id==‘abc’


#6

I think I found the culprit…
There exists a record of SummaryBill whose parent.resource.id==‘jkl’, and it has:

peakDemand: {unit: {id: 'MLBH'}}
consumption: {value: 10, unit: {id: 'MLB'}}

This record that does not have the value field populated on peakDemand causes the error. But value is not a required field on ExactDimension, so I’m not sure why this would be an error…

Yet even with my “fix” the two new fields are not populated at all for this SummaryBill…


#7

@sean.summers I would file a ticket and include your findings.