Working With Indices
Now let's look again at ^PersonI and Traverse(). In the example, even though ^PersonI can have up to four subscripts, we're traversing the children of the root: the first dimension. Traverse() returns the first valid subscript, in this case, “DOB”. Passing “DOB” as the subscript in turn returns the next valid subscript, “Name”. Passing “Name” returns “Phone”, and passing “Phone” causes Traverse() to return the empty string.
When we use Traverse() to traverse this level, it returns one of each subscript. In the view shown here, “DOB”, “Name”, and “Phone” repeat three times. This isn't an error, it's just the Portal's way of displaying globals. There is only one “DOB” node, one “Name” node, and one “Phone” node in the tree.
The Traverse() examples on the next six pages (including this one) only run after you've stored at least one person in the database, in the SAMPLES namespace, as the hands-on exercises specify.
println "first node of ^PersonI is: ", traverse( ^PersonI("") )
println "node after ""DOB"" is: ", traverse( ^PersonI("DOB") )
println "node after ""Name"" is: ", traverse( ^PersonI("Name") )
println "node after ""Phone"" is: ", traverse( ^PersonI("Phone") )