Question Vivian Lee · Sep 13, 2024

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?

Product version: IRIS 2022.1

Comments

Robert Cemper · Sep 13, 2024
if$d(^|"%SYS"|CONFIG("Namespaces"," "))
 forset ns=$o(@$ZR) quit:ns=""write ns,!  ; or do whatever you intend
0
Phillip Wu  Jun 19 to Robert Cemper

Can 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,!

0
Robert Cemper  Jun 20 to Phillip Wu

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 !

0
Vivian Lee · Sep 13, 2024

$ORDER works perfectly. Thank you all!

0