Sebastian Mueller · Aug 25, 2016

Iterate through global

Let's imagine I have a global like this:

^Users(12, "SETTINGS", "IsAllowed") = 1

^Users(41, "SETTINGS", "IsAllowed") = 0

^Users(52, "SETTINGS", "IsAllowed") = 1

Now I would like to check for each user whether they are allowed, therefore I'd need to iterate through the Global. How to do that? It seems that I can't use $Order here like such:

S FF = ""
For {
 S FF=$O(^Users(FF,"SETTINGS","isAllowed"))
 W "User ",FF," is allowed",!

Is there any other way of doing this? 

0 792
Discussion (5)1
Log in or sign up to continue

You can use $order to order all users, in global

set FF=""
for {
  set FF = $order(^Users(FF))
  set isAllowed = $get(^Users(FF, "SETTINGS", "isAllowed"))
  write:isAllowed !,"User ",FF," is allowed"

Hi Sebastian,

Set FF = ""
For {
 Set FF=$Order(^Users(FF))
 If FF="" Quit
 If $Get(^Users(FF,"SETTINGS","isAllowed"))=1 {
  Write !,"User ",FF," is allowed"


set key = $O(^Users(""))

While key '= ""


     if ($DATA( ^Users(key,"SETTINGS","isAllowed"))>0)


                set isAllowed = ^Users(key,"SETTINGS","isAllowed")


      set key = $O(^Users(key))


Note that Dmitry's answer and mine are pretty much the same, except that I like to avoid post conditional commands where it´s not strictly needed  wink

$Query may help, but more likely to be 

S FF = ""
For {
    S FF=$O(^Users(FF))

    I '$D(^Users(FF,"SETTINGS","isAllowed"))#2    {

        W "No settings for user "_FF
    } elseif ^Users(FF,"SETTINGS","isAllowed") {

        W "User ",FF," is allowed",!
    } ELSE {
         W "User ",FF," is not allowed",!

(That assumes the 1/0 value determines whether the user is / is not allowed rather than the existence of the node)