Scott Beeson · Jan 21, 2016

Custom function to retrieve environment?

I want to do some logic based on what environment code is running in. I can't find a built-in function to retrieve this so I'd like to write a custom function. Does anyone know of a command that would get the current environment?

0 582
Discussion (9)4
Log in or sign up to continue

What do you mean by environment ? In Cache we dont have such term.

Maybe you mean System Mode  on page "Memory and Startup" Page. If so,  that value only stores in global here ^%SYS("SystemMode")

HSREGISTRY>w ^%SYS("SystemMode")


That's exactly what I want!  Thanks!

Another option, and a caveat about ^%SYS("SystemMode"):

It looks like you're using CCR.* "Environment" is a meaningful term in that context. In namespaces configured for CCR, you can retrieve the environment with $$Env^%buildccr, i.e.:

CCR>w $$Env^%buildccr

It is possible to have multiple namespaces on the same instance configured as different environments. ^%SYS("SystemMode") is set to the furthest-along environment (of BASE-TEST-LIVE) of any namespace on the instance. That is, if you have a namespace configured as BASE, and configure another one as TEST, ^%SYS("SystemMode") will be changed to TEST - and this is system-wide. Just something to keep in mind.

*CCR (Change Control Record) is an InterSystems in-house application used in sites where InterSystems does implementation work, so this isn't as generally relevant as ^%SYS("SystemMode").

We do use CCR, this will be useful in my decision.  Thank you.

personally i would use

set mode=$System.Version.SystemMode()

which is documented and therefore a supported API. This package provides a wealth of classes and methods.

Look at documatic for the %SYSTEM package.

When I try this from a terminal it tells me the method does not exist.  Am I missing something?

NAMESPACE>w $System.Version.SystemMode()
W $SYSTEM.Version.SystemMode()

It looks like that method only exists in Caché 2015.2.0+. You're probably running on an older version.

(write $zversion?)

Yep, 2015.1.1 

Oh well.  I think I have what I need.  Thanks.