Arg not passed properly to function in helper

#1

I have implemented a custom function into the helper but to the function instead to be passed the value of debitReconstructedEnergy that is 8.8 it is passes the string “debitReconstructedEnergy” - how can I pass the value of debitReconstructedEnergy to the custom function?
of course debitReconstructedEnergy is retrieved from the collection
The arg source.revenueOpportunities is passed properly

{
“id”: “EnergyLastInspection”,
“label”: “{~RevenueProtection.ListComponent.columns.LastDebitRecon.label~}”,
“field”: “source.revenueOpportunities”,
“format”: {
“funk”: “lastDebitReconstructedEnergy”,
“args”: [“debitReconstructedEnergy”]
},
“align”: “center”,
“sortable”: false,
“wordWrap”: “break-word”,
“width”: 80
}

#2

The args passed to the formatting function are not resolved, but only the first value which is resolved from field. This means that whatever you put in args it will be passed as is to the function defined in funk.

This is why you’re seeing debitReconstructedEnergy passed and not record.debitReconstructedEnergy.

#3

If anyone can help to fix would be great - with that paramaeter available I can avoid to perform fetch within my custom function and save execution time and db calls

#4

One option is to specify “record”: true in your formatting options:

"format": {
    "record": true,
    "funk": "lastDebitReconstructedEnergy",
    "args": {
        "fields": [
            "debitReconstructedEnergy"
        ]
    }
}

Then, in your js definition get the value of the attribute using C3.util.getDescendantProp():

value = C3.util.getDescendantProp(item, field);

In the same way you can get the array in source.revenueOpportunities:

value = C3.util.getDescendantProp(item, 'source.revenueOpportunities');

1 Like