Question
· 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?

Discussion (9)2
Log in or sign up to continue

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
BASE

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").