Question
· Jun 27, 2023

Getting error method does not exist *%New on class name

I am creating a class code below

Class Sample.Header

{

Property Key As %String;

Property Show As %Boolean;

}

when I am trying to create an object of this class

using set obj = ##class(Sample.Header).%New()

getting error <METHOD DOES NOT EXIST> %New, Sample.Header

Product version: IRIS 2023.1
Discussion (3)3
Log in or sign up to continue

In IRIS there are no built-in constructors. Classes that don't inherit from a system class are usually used as storage for class methods.  Therefore, if you want to create an object you need to inherit your own class from one of the system classes, like %RegisteredObject (won't save your objects to the database), %SerialObject (won't save your objects to the database on its own), %Persistent (will save your objects to the database) etc. For example:

Class Sample.Header extends %Persistent
{
Property Key As %String;
Property Show As %Boolean;
}