Question
· Jun 28, 2022

Is it possible to call a method in a specific namespace without changing current namespace ?

I want to call a method which is in %SYS namespace : 

set NS = $NAMESPACE
ZN "%SYS"
do ##class(Config.MapGlobals).Delete(...)
ZN NS

In reality code is even more complex (eg: need a try catch block to make sure namespace is switched back even if there is some error).

Is it possible to do this without changing current namespace ?
For example (does not work) :

do ##class(%SYS.Config.MapGlobals).Delete(...)
Product version: IRIS 2022.1
Discussion (4)1
Log in or sign up to continue

First, the correct (or better) way for the above code snipet were:

new $NAMESPACE
zn "%SYS"
do ##class(Config.MapGlobals).Delete(...)
quit

second, one can call routines (and (class)methodes are compiled to rotines) from another namespace by using extended syntax, but in that case such a routine uses the globals (if the routine does a global access) from the CALLING namespace. In Your case this won't work because the Config.MapGlobals uses globals which resides in %SYS namespace and not in the namesspace you are in.

The general syntax for calling routines from another namespace is:

do label^|namesapce|routine

where

- you can omit the label and

- namespace is either the name of the namespace (like set namesapce="USER") or the path to the database (preceded by two carets), where the routine resides.

I see right now, Config.MapGlobals accesses the ^SYS global via the path to the database (take a look at the Storage section) - so in theory, you  can  call all classmethods from the above class as:

do zClassmethodname^|"%SYS"|Config.MapGlobals.1(args...)

merely, I do NOT recommend to do this (the cass is in deployed mode, so we do not know, what the code really does and (instance)methods are private, so you can't call them from outside).