<METHOD DOES NOT EXIST> Error getting when call method from ClassMethod.
Hi Team,
I am getting the below error while calling Method from ClassMethod in the same cls file.
Please help me with this, So It would be very helpful for me.
|
Product version: IRIS 2021.1
calling Method from ClassMethod
This is the problem. A Method needs to be called in the context of an instantiated object. A ClassMethod by definition isn't associated with an instantiated object.
If it's necessary to do it this way, your ClassMethod could use %New() to instantiate an object and then call the Method on that object:
But, it looks like you're working with a Business Service class. For that, it isn't enough to simply use %New(). You need to use Ens.Director::CreateBusinessService to instantiate the object before calling the Method.
https://docs.intersystems.com/irisforhealth20212/csp/docbook/DocBook.UI....
A thumbs up to Marc who explained the same method distinction I did, but went the extra mile to explain how to instantiate a business component (with doc link)!
SendRequestSync is an object method that requires an object as the base.
##class(Ens.BusinessService).SendRequestSync( works for ClassMethods only.
You need an object instance of Ens.BusinessService to call it.
##class(Ens.BusinessService).%New().SendRequestSync(
might be a dirty workaround
Harshdeep,
You're trying to call a method like a class method. For a "method" you need to have an instance of the object to use the method, "class methods" can be called without an object reference.
See docs here:
Defining and Calling Methods