Article
· May 25, 2023 2m read

API to import/export routines

This is an article on the InterSystems FAQ site.

 1. Export API

a. Use $system.OBJ.Export() to specify individual routines to export. For example:

do $system.OBJ.Export("TEST1.mac,TEST2.mac","c:\temp\routines.xml",,.errors)

The format to specify is routine name.extension, and the extension is mac, bas, int, inc, obj.

Errors during export are stored in errors.

See the class reference %SYSTEM.OBJ for details on $system.OBJ.Export().

b. Use $system.OBJ.Export() even when exporting with wildcards. For example:

do $system.OBJ.Export("*.mac",c:\temp\allmacroutines.xml")

*Before version 2008.1, use $system.OBJ.ExportPattern().

c. Use $system.OBJ.ExportUDL() for individual export rather than export in xml format. For example:

do $system.OBJ.ExportUDL("myclass.cls",c:\temp\myclass.cls")

 

2. Import API

a. Use $system.OBJ.Load() to import all routines contained in the file. For example:

do $system.OBJ.Load("c:\temp\routines.xml",,.errors)


b. Import only some of the routines contained in the file

If you want to select and import only some of the routines included in the XML file, set the 5th argument listonly to 1 once to load the XML file with $system.OBJ.Load(), and set the 4th argument (output argument ) to select the import target from the list obtained and specify it with the 6th argument. For example:

 Set file="c:\temp\routines.xml"
 // First get the list of items contained in the XML
 Do $system.OBJ.Load(file,,.errors,.list,1 /* listonly */)
 Set item=$Order(list(""))
 Kill loaditem
 While item'="" {
     If item["Sample" Set loaditem(item)="" {    // Import only those containing Sample
         Set item=$Order(list(item))
     }
 }
 // Execute import process with created list
 Do $system.OBJ.Load(file,,.errors,,,.loaditem)

 

c.  You can also use $system.OBJ.ImportDir to import multiple files under that directory.  For example:

do $system.OBJ.ImportDir("c:\temp","*.cls","ck")
Discussion (2)2
Log in or sign up to continue