Subclass Property Retrieval
I have a sub class that calls a method in the parent class it is derived from.
However in the below code a <NO CURRENT OBJECT> error is thrown.
Using the debugger I can see $THIS is returning the name of the subclass as it should and name is the correct property name (worth noting some properties are defined in the superclass not the subclass).
Why is this error ocouring and how can I fix it?
Product version: IRIS 2021.1
It looks like a problem of $THIS, if you check the documentation (here) you'll see that the relative dot (..) notation is preferred, in the same page you can see that <NO CURRENT OBJECT> error is produced by a bad reference of the object.
You can check the documentation about the relative dot notation here
Can you please provide here a small sample showing the issue.
$this is actually return the current class name instead of object if you're using inside ClassMethod. On the other hand if you use $this (It actually holds the object) So, it returns object inside Method . Check the below sample code and output
ClassMethod thistest() { write "$this inside ClassMethod: ",$this,! write "$this object check ClassMethod: ",$ISOBJECT($this),! set obj = ##class(User.NewClass1)..%New() do obj.thistest1() } Method thistest1() { write "$this Method: ",$this,! write "$this object check Method: ",$ISOBJECT($this),! }
So. If you're trying to get the property value inside classmethod by using $this in $PROPERTY($THIS,propertyName) It throws <NO CURRENT OBJECT> error . so you should use object for $PROPERTY or use this retrieval $PROPERTY($THIS,propertyName) inside method.