· Oct 25, 2023

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.

Set propertyValue = $PROPERTY($THIS,name)

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
Discussion (4)3
Log in or sign up to continue

$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),!
LEARNING>d ##class(User.NewClass1).thistest()
$this inside ClassMethod: User.NewClass1
$this object check ClassMethod: 0
$this Method: 1@User.NewClass1
$this object check Method: 1

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.