Objects that are no longer in datasource still tries to calculate a runtime function parameter (and fail)

Hi
I have a datasource with a runtime function parameter that calculate a line price based on quantity and price, something like this:
if (!quantity) return price*quantity

My issue is that if this object is removed from the datasource by setting a flag (deleted=true is the datasource filter), the function still tries to execute the function parameter to get the line price, even though the object is no longer in the datasource. This generates errors which I want to get rid of.

||message: Error running function: Cannot read properties of undefined (reading ‘quantity’),|
|—|—|
||functionName: fn49074aa3,|
||functionParameters: [|

This error is shown in dev console every time an object is removed.

Is it possible to avoid the errors without changing the way the datasource behaves? It does not help to check if quantity is set since the object itself is no longer in the datasource.

This looks like some kind of timing issue, the function parameter is executing on objects that no longer exist in the datasource - and fails because the object is no longer there.

Regards

Hi Johan,

As a possible solution to removing these error messages from the console, you could look at implementing nullish coalescing. This is a way to control the output or logic based on if a variable or property is null/undefined.

In this case, you could do something like:

let quantityToUse = quantity ?? 0
let priceToUse = price ?? 0
return quantityToUse * priceToUse

In this case, if either quantity or price are null, the sum will return 0.

Thanks
Rhys

Hi Rhys
Thanks for your suggestion. I tried it out but the issue remains. The error is happening when trying to read the self property quantity on an object which is no longer in the datasource (which triggers a formula recalculation). quantity is one of my function params. So it does not really matter what I do inside the function.

If i just do “return 0” in the function and keep my function properties, the error is still displayed when an object is removed. It does not matter if I use the self property or the database connected property.

Hi,

This is not a general case, just tested various scenarios of the same, without any luck of recreation any error message in the log.

Can you try to isolate the case (e.g. recreate in a separate app), and provide more info on the data source setup, the function setup itself, and how the action is set up?

Thanks.
After trying to remove all function parameters it turns out the issue is not where I thought it was after all. The problem now is to find out where the issue is caused. I have a function ID but afaik I can´t pin point where this is based on the function id?

Error running function: Cannot read properties of undefined (reading ‘quantity’)

2
{
“message”: “Error running function: Cannot read properties of undefined (reading ‘quantity’)”,
“functionName”: “fn49074aa3”,
“functionParameters”: [
{
“id”: “otIjkM”,
“name”: “orderline”,
“functionParameterType”: “data_source”,
“dataSourceId”: “uYNfDK”,
“selectionType”: “filtered”,
“filterDescriptor”: {
“id”: “4sffXU”,
“nodeType”: “group”,
“sourceDataSourceId”: “uYNfDK”, (Orderline)
“operator”: “$and”,
“nodes”: [
{
“id”: “WUqKdG”,
“nodeType”: “edge”,
“operator”: “$eq”,
“targetType”: “reference”,
“targetDataSourceId”: “fLsJ6x”, (Product)
“sourceDataSourceId”: “uYNfDK”,
“sourceNodeName”: “product”,
“sourceDataType”: “reference”,
“isSourceCardinalityMany”: false,
“targetNodeName”: “_id”,
“isBaseTypeObjectId”: true,
“targetDataSourceCardinality”: “MANY”,
“targetSelectionMode”: “selected”
}
]
},
“parameterCardinality”: “MANY”,
“nodeNamesInUse”: [
“quantity”,
“order”
]
}
],
“functionId”: “49074aa3”,
“arguments”: {
“AF_LOGGER”: {
“id”: “332de9e7”,
“logName”: “default”,
“root”: null,
“parent”: null,
“enabled”: true,
“level”: 1,
“metadata”: {
“prefix”: “Appfarm”
},
“transports”: [
{
“id”: “console”,
“level”: 1
},
{
“id”: “devToolsLog”,
“level”: 1
}
],
“children”: ,
“timers”: {}
},
“orderline”:
},
“error”: {}
}

The property “quantity” is used a lot of places throughout the app, and in many views (not active though) and actions, but it does not seem to happen in an action.

I know the two data sources referenced in the error are Orderline and Product…
From the error it looks like its a function parameter that is recalculated and the only place Im aware of is … the place I was working on.

Just to chime in,
Is the code example that you provided correct?

You seem to check if quantity has value, and if it doesnt you attempt to use it. Is that correct?

Hi
Thanks for following up.
I havent had the time to track this down yet but I verified that it is not a general issue as Kristian pointed out so it must be some kind of dependency issue when removing an object.

No, the code was not correct, the check was: if (!quantity) return 0