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?
Comments
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")
TEST
That's exactly what I want! Thanks!
Converted to an answer.
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").
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?
W $SYSTEM.Version.SystemMode()
^
<METHOD DOES NOT EXIST> *SystemMode,%SYSTEM.Version
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.