go to post Andrey Tverdokhlebov · Jun 23, 2022 Yup, that's simpler way to do it instead of $Q. It's same as this: s sub="" F s sub=$O(^je1("NotConfigured",sub)) Q:=sub="" w sub,! just without redirection. The main key here if you are looking for just sub script level then $O is what you need. If you want whole global ref, then aka instead of getting just CBB or CH11 you would get ^je1("NotConfigured","CBB"). In your case this would exit the loop since your loop is looking at $Q(@node) where node = ^je1("NotConfigured","CBB") instead of ^je1("NotConfigured") and since there is no sub script at that level your loop quits (hence only why you get the first level from your initial Set command). So your code should look like this for $Q to work: Set node = "^je1(""NotConfigured"")" WRITE !,node FOR { SET node=$QUERY(@node) QUIT:node="" WRITE !, node } $Q is useful when you want to check what level exist under a global which may be defined dynamically or something close to that, but $O does the job for everything else.