Hi there,
I am getting an error Cannot read property 'hasOwnProperty' of undefined
which I cannot identify or replicate. Is there a usual source of such errors I should be aware of?
Thanks
Hi there,
I am getting an error Cannot read property 'hasOwnProperty' of undefined
which I cannot identify or replicate. Is there a usual source of such errors I should be aware of?
Thanks
could you please provide a service name and method where this error occurred?
Sure, the service name is BG_Recurring_Notifs and the method is Recurring_email_notifs.
App ID: 4A47197B-AE30-FA84-FF56-0071F4010900
Thanks! Checking it…
This error can only occur if the block Get property .. of ..
receives a not an object type value in the of
input. Unfortunately, due to our latest release, we have worsened the readability of the error and now it is difficult to understand exactly where an attempt is made to read a value from a non-object. We will fix this soon, and I apologize for the string of these regressions. Right now, while the fix is being prepared and goes through all the testing stages, I recommend trying to independently find out the place where a non-object is passed to the block, and then you already need to understand why a non-object comes there.
Alternativelly you may create a custom code block with the following code inside:
if (!object) {
throw new Error(`Cannot read properties of not an object (reading '${propPath}')`)
}
if (typeof propPath !== 'string' || object.hasOwnProperty(propPath)) {
return object[propPath]
}
const propsNamesList = propPath.split('.')
let result = object
for (let i = 0; i < propsNamesList.length; i++) {
if (!result || !result.hasOwnProperty(propsNamesList[i])) {
return
}
result = result[propsNamesList[i]]
}
return result
It will accept two arguments - object
and propPath
.
Regards,
Stanislaw
ok I understand, so somewhere in the method, we are using Get property .. of ..
and instead of an object, there is a string or an array or something else, correct?
Yes, but from the error text, it receives undefined
.