Written by

Senior Startups and Community Programs Manager at InterSystems Corporation
Question Evgeny Shvarov · Nov 30, 2017

How to Map Class Package to a Namespace Programmatically

Hi folks!

Is there a one line command to map class package A to Namespace ASPACE?

Comments

Dmitry Maslennikov · Nov 30, 2017

Something like this, but in %SYS namespace. Documentation

%SYS>s props("Database")="SAMPLES",sc=##Class(Config.MapPackages).Create("USER","PackageA",.props)

0
Evgeny Shvarov  Nov 30, 2017 to Dmitry Maslennikov

Thanks, Dmitry!

Though the parameter for a 'namespace-to-map' with a name "Database" looks weird.

0
Eduard Lebedyuk  Nov 30, 2017 to Dmitry Maslennikov

Note: if you want to add a large number of mappings, you should first save all new mappings and then activate the new config file afterwards.

This is applicable to all Config modifications.

0
Evgeny Shvarov  Nov 30, 2017 to Evgeny Shvarov

Nevermind, everything works fine!

Just to be clear: your line of code shows how to create the mapping of PackageA in Database SAMPLES to Namespace USER.

0
Evgeny Shvarov  Nov 30, 2017 to Eduard Lebedyuk

What do you mean by 'config file'?

0
Eduard Lebedyuk  Nov 30, 2017 to Evgeny Shvarov

cpf files.

All classes from Config package affect one of cpf file (active one by default). But you also need to save and activate modified config file. Dmitry solution does that all by default. Which is fine if you want to add one mapping, but if you want to modify several Config settings it's better to modify them and activate the changes separately. For example here's mapping several packages to %ALL.

#include %syConfig
set namespace = "%ALL"
set namespace = $zcvt(namespace, "U")
for package = "Package1","Package2","Package3" {
    kill p
    set p("Database")=pFrom
    set sc = ##Class(Config.MapPackages).Create(namespace, package,.p,,$$$CPFSave)
}
set sc = ##Class(Config.CPF).Write()
set sc = ##Class(Config.Map).MoveToActive(namespace)
set sc = ##Class(Config.Namespaces).Load(namespace)
0
Evgeny Shvarov · Nov 30, 2017

This is similar documentation for mapping Routines.

And one note: if you map routines, put the routine name without extension.

E.g. if you want to map MyMacro.inc from USER to %ALL run the following in %SYS namespace:

%SYS>s props("Database")="USER",sc=##Class(Config.MapRoutines).Create("%ALL","MyMacro",.props)
0