Cannot convert null to and object in v3.1.5

In trying to convert from v2.2.7 to 3.1.5 I’m getting the following error…

Cannot convert null to an object.
Callstack:
SOSTRS_Production_Facility_Detail.showDetails
SOSTRS_Production_Facility_Detail.onShow
TypeError: Cannot convert null to an object. (showDetails; line 11)
SOSTRS_Production_Facility_Detail.showDetails
SOSTRS_Production_Facility_Detail.onShow

When I look at that line of code in the showDetails method I see this…

	if(sostrs_to_sosord.lquote == 1 || sostrs_to_sosord.lvoid == 1)

I have checked the relations and they work perfectly elsewhere and are based on a single 10 digit text field in each table. The fields the relations refer to, lquote and lvoid, are both integers.

Everything replaces properly from the Debuggers Navigator Tree.

Is there some new syntax in 3.0 that’s not evident?

Thanks in advance for your help!

What if the relation has no records? If I use a relation like that, I always test by databaseManager.hasRecords().

As Patrick says (and I…) first do a databaseManager.hasRecords(relation) check.
When there are no records on either side this will be captured by it.
Even if you think the relation can never be wrong you should still check.

I am sure the relation works great. But you are asking that relation (which is actually a foundset) for a certain property (a field value). And if the foundset is null, then you ask null.property. Properties belong to objects, so you get “cannot convert null to an object”.

Here is what I tried… (great suggestion BTW, because I’ve used that everywhere else, just not here… and thanks for the exact explanation)…

	if(databaseManager.hasRecords(sostrs_to_sosord) && sostrs_to_sosord.lquote || sostrs_to_sosord.lvoid)

But I’m still getting the same error…

Try to change it to:

if(databaseManager.hasRecords(sostrs_to_sosord) && (sostrs_to_sosord.lquote || sostrs_to_sosord.lvoid)) 

In your version, even if there are no related records, it will try to evaluate sostrs_to_sosord.lvoid…

Hope it works then.