Written by

Question Phillip Wu · Feb 3

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

Comments

Robert Cemper · Feb 3

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,!
 }
 quit
0

FYI 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)
0
Phillip Wu  Feb 3 to Guillaume Rongier

Thanks to everyone for the quick replies.

Much appreciated the Python solution to the question

0