Load ObjectScript external file and run code
Hi,
I have Objectscript routine stored in an external Linux file which I've called /my/home/DisplayDB.int
This file does not include any Class definitions and is simply a set a Object script routines. I think this is called INT objectscript
The file looks like this:
set db=##class(Config.Databases).DatabasesByServer("",.dbList)
for i=1:1:$LENGTH(dbList,",") {
set dbName= $PIECE(dbList,",",i)
write dbName,!
}How do I load and compile the Objectscript code?
Do $system.OBJ.Load("/my/home/DisplayDB.int", "ck")
How would I run the code?
do ^DisplayDB
Thanks in advance for any help
Discussion (0)0
Comments
Your file format doesn't fit, but you are close.
UDL Header is missing, also leading blanks in the lines as you have no labels.
And you have to switch to namespace %SYS and back to make it work.
ROUTINE DisplayDB[Type=INT]
new$namespacezn"%SYS"set db=##class(Config.Databases).DatabasesByServer("",.dbList)
for i=1:1:$LENGTH(dbList,",") {
set dbName= $PIECE(dbList,",",i)
write dbName,!
}
quitFYI in python :
import iris
iris.system.Process.SetNamespace("%SYS")
db_ref_list = iris.ref(None)
iris.cls("Config.Databases").DatabasesByServer("", db_ref_list)
db_list = db_ref_list.value
db_names = db_list.split(",")
for db_name in db_names:
print(db_name)Thanks to everyone for the quick replies.
Much appreciated the Python solution to the question