Question
· May 10, 2019

Get parent classname

Hi community.

I need to get the parent classname of a class, but I don't find how to do it.

 

I have a class Parent  (MyLibrary.ParentClass) and two classes inherited from the parent class

MyLibrary.ParentClass

       ├─── MyLibrary.ChilcClass01
       │
       ├─── MyLibrary.ChildClass02

I have a Business Process that entry class is MyLibrary.ParentClass. If I'm calling with any child class (i.e. MyLibrary.ChildClass01) it works, then I'm using the method $Classname(request) to get the name of the class and redirecto to other process.

But I want to check that the request is a class inherited from MyLibrary.ParentClass. How to do it?

 

Best regards,

Francisco López

Discussion (3)2
Log in or sign up to continue

Well, next time I need to read the documentation in depth.

There is a base method to check if a class extends of other one

set obj = ##class(MyLibrary.ChildClass01).%New()

## this retrieves 1
w obj.%Extends("MyLibrary.ParentClass")

## this retrieves 0
w obj.%Extends("MyLibrary.ParentClassFake")

This has been a "Rubber duck", this is a sample of guide-book of rubber duck. wink

More info Clase %Library.SystemBase

Best regards,

Francisco López

Be careful. %Extends returns 1 | 0 but it is checking the entire SUPER value of your class, not just the primary superclass. Take a simple class that extends both MyLibrary.ParentClass and %Library.Populate - %Extends will return 1 (true) for both MyLibrary.ParentClass and %Library.Populate.

There is another method - %IsA(superclass) that returns 1 (true) only if the superclass is the primary super class (forms a %IsA() relationship with your current class).