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
Hi Gautam,
As it stands your class is not an object class (https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...).
In order to instantiate an object, make sure the class inherits from %RegisteredObject or a subclass of it.
We do this in ObjectScript as follows:
Class Sample.Header Extends %RegisteredObject { /// your code }
Thanks it worked.
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; }