Iterate over array of namespaces
How do you iterate over the array of namespaces returned in the result byref from the call below?
DO ##class(%SYS.Namespace).ListAll(.result)Running "zw result" displays the namespaces (as individual subscripts in result) in the Terminal but I want to be able to programmatically iterate through each namespace name.
The documentation for ListAll() mentions here that result will be a local array name passed by reference. Is there a way to turn it into a dynamic array?
Comments
w ##class(%SYS.Namespace).ListAll(.out) is what I would use and just $order over it
https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic…
Here's some sample code from an open-source project if you'd like to copy:
https://github.com/intersystems/git-source-control/blob/82d740af3ac035f…
if$d(^|"%SYS"|CONFIG("Namespaces"," "))
forset ns=$o(@$ZR) quit:ns=""write ns,! ; or do whatever you intendCan you please explain what this code does?
If I run:
DO ##class(%SYS.Namespace).ListAll(.result)
zwrite result
I get:
result("%SYS")=""
result("USER")=""
....
So how does this code work?
if $d(^|"%SYS"|CONFIG("Namespaces"," "))
for set ns=$o(@$ZR) quit:ns="" write ns,!
straight ObjectScript
USER>if$d(^|"%SYS"|CONFIG("Namespaces"," ")) ;; position $ZR in CONFIG
USER>forset ns=$o(@$ZR) quit:ns=""zwrite ns ; list it
ns="%SYS"
ns="SAMPLES"
ns="USER"
USER>BINGO !
$ORDER works perfectly. Thank you all!