Variables in Global Name
I have a number of globals I want to loop through depending on a passed in string...
^A("SYSTEM")
^B("SYSTEM")
^C("SYSTEM")
^D("SYSTEM")
^E("SYSTEM")
I am passing in a string of "A:C:D"
Piecing that to pull out A,C,D, then want to use that to pull out A,C,D from above, but having problems setting the name of the global to be the name of the variable I have pulled out of the string
How do I set this?
I have tried ^varname("SYSTEM")
also tried setting a variable to have the value "^varname" and using that
Thanks
what you are looking for is called global indirection
https://docs.intersystems.com/iris20201/csp/docbook/DocBook.UI.Page.cls?KEY=GGBL_using#GGBL_using_indirect
write $d(@myglobal@(12))
write @myglobal@(12,sub2)
and so on
Hi
So you can use global indirection here:
you can set a variable to the name of a global
you can then do either of the following:
or you can use it to reference nodes within the global root:
you can also do this:
which effectively reads
so before this I executed the following line of code:
if you want to use this across namespaces then you need to do the following:
this then reads as:
Yours
Nigel
Just as a note, where you are manually building up your global in gbl you could use the $name function instead, for example...
set gbl="^NigelGlobal(""Subscript1"""_","_"""Subscript2"")"
can be
set gbl=$name(
^NigelGlobal("Subscript1","Subscript2"))
which makes it easier to handle quotes etc...
update: ignore the very odd formatting this editor applied to the objectscript.