@@ -5,9 +5,16 @@ Class User.Foreach
55// Example of how to use the foreach functionality 
66ClassMethod  SampleMethod () as  %Status  {
77try  {
8- //set message = {} 
8+ // Troubleshooting vars for dynamic objects and arrays, activate as needed 
9+ set  message  = {}
10+ set  message .sidjfdf  = " Dynamic 1" 
11+ set  message .sdjfs  = " " 
12+ set  message .sdiofsoi  = " Dynamic 2" 
13+ /* 
914set message(1) = "thing 1" 
1015set message(2) = "thing 2" 
16+ */ 
17+ // Pass the object, the function we want run, and our class location to the foreach 
1118do  ..Foreach (.message , " Action" $this )
1219}
1320catch (e ) {
@@ -31,14 +38,13 @@ ClassMethod Foreach(ByRef pVal, pFunc, pClass) As %Status {
3138try  {
3239// We get the key value pairs from our dynamic object 
3340set  tIter  = pVal .%GetIterator ()
41+ if  tIter  = " " throw 
3442// Loop through these values and add to our query depending on their contents 
3543while  tIter .%GetNext (.key , .value ) {
36- if  value  '= " " 
37- // We pass the value to the action 
38- // TODO: Add ability to capture value and key in a friendly way 
39- do  $classmethod (pClass , pFunc , value )
40- //write key_"='"_value_"'",! 
41- }
44+ // We pass the value to the action 
45+ // TODO: Add ability to capture value and key in a friendly way 
46+ do  $classmethod (pClass , pFunc , value )
47+ //write key_"='"_value_"'",! 
4248}
4349}
4450catch  (e ) {
@@ -59,23 +65,4 @@ ClassMethod Foreach(ByRef pVal, pFunc, pClass) As %Status {
5965}
6066return  $$$OK
6167}
62- 
63- // Iteration over an object 
64- ClassMethod  Foreachs (ByRef  pVal , pFunc , pClass ) As  %Status  {
65- try  {
66-  // Element position init 
67-  set  tStruct =" " 
68-  // Loop through the array 
69-  for  {
70-  set  tStruct =$order (pVal (tStruct ))
71-  quit :tStruct =" " 
72-  // Perform our action method on each element 
73-  do  $classmethod (pClass , pFunc , pVal (tStruct ))
74- }
75- }
76- catch  (e ) {
77- write  " Foreach error " e .Name 
78- }
79- return  $$$OK
80- }
8168}
0 commit comments