Written by

Integration Engineer at ReStart Consulting
Question William Glover · 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

Comments

Luis Angel Pérez Ramos · Oct 25, 2023

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.

0
Alexander Koblov · Oct 25, 2023

Can you please provide here a small sample showing the issue.

0
Ashok Kumar T · Oct 25, 2023

$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.

0