Question
· Feb 4

Calling a class from another Namespace

Hello everyone,

I am looking for the syntax or the way to use a class created in the "BNA" Namespace (my application) from the %SYS Namespace.

Here is the context:

I have a "BNA" application contained in the "BNA" NS, this application provides a user creation functionality. This feature creates both the user in a table in the application and in the Iris system.

I created an initialization script for my database to be able to reset it at will, this script starts by emptying the database of this data, then initializes the basic data. We are testing the user creation functionality, which we are doing with an e2e tool (cypher). During these tests, we create around fifteen users with auto-generated logins.

In my script I know how to easily delete users in the application, but for Iris users I started a method to retrieve user IDs and then delete them. For the moment I have only developed the selection and I want to use a method of a class of my application (##class(Bna.Utils.Sql).SelectFirstColsInArray()) which returns me a dynamic array.

ClassMethod RemoveIrisTestUsers() As %Status
{
	New $NameSpace
	Set $NameSpace="%SYS"
	// Get test users by login begining
	Set query = "select * from Security.Users "_
				"where "_
    				"ID like LOWER('ARS%') or"_
		    		"ID like LOWER('CHERCHEUR%') or"_
    				"ID like LOWER('CS%') or"_
    				"ID like LOWER('DGOS%') or"_
					"ID like LOWER('CENTRE%')"
	Set sc = ##class(Bna.Utils.Sql).SelectFirstColsInArray(query, .userIds)
	if 'sc Return sc
	zw userIds

	Return $$$OK
}

 At run I get : 

<CLASS DOES NOT EXIST>RemoveIrisTestUsers+11^Bna.Init.Main.1 *Bna.Utils.Sql

Which is normal, given that I moved to the NS "%SYS", hence my question:

Calling a class from another Namespace?

An alternative would be to stay in the NS "BNA", but in this case it is the $Security.Users table which is not accessible, hence my second question.

Is there a way to map a table from one NS to another?

PS: I know perfectly well without using my ##class(Bna.Utils.Sql).SelectFirstColsInArray() method, but I would like to know the possibilities of working between the NS

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

Hi @Pierre LaFay 

Define a Method instead of  ClassMethod and Instantiate the object for that class and call the required method. It will work

Class Bna.Utils.Sql Extends %RegisteredObject
{

ClassMethod RemoveIrisTestUsers() As %Status
{
    set obj = ..%New()
    New $NameSpace
    Set $NameSpace="%SYS"
    // Get test users by login begining
    Set query = "select * from Security.Users "_
                "where "_
                    "ID like LOWER('ARS%') or"_
                    "ID like LOWER('CHERCHEUR%') or"_
                    "ID like LOWER('CS%') or"_
                    "ID like LOWER('DGOS%') or"_
                    "ID like LOWER('CENTRE%')"
    Set sc =obj.SelectFirstColsInArray(query, .userIds)
    if 'sc Return sc
    zw userIds

    Return $$$OK
}

Method SelectFirstColsInArray(query, test)
{
    zwrite query,test
    return $$$OK
}

}