StructFindValue
Searches a struct for a given value and returns an array of results
Method Signature
StructFindValue(struct=[structloose], value=[string], scope=[string])
Arguments
struct
struct
true
The struct to search
value
string
true
The value to search for
scope
string
false
Either one (default), which finds the first instance or all to return all values
one
Examples
Find first match for a nested struct value
myStruct = {
A : 2,
B : 4,
C : 8,
D : 10,
E : 12,
F : 12
};
myStruct.MYSECONDSTRUCT = {
A1 : 50,
A2 : 12
};
myStruct.MYSECONDSTRUCT.MYTHIRDSTRUCT = {
B1 : 12,
B2 : 65
};
myValue = StructFindValue( myStruct, "12", "one" );
WriteOutput( JSONSerialize( myValue ) );
Result: [{"path":".E","owner":{"A":2,"B":4,"C":8,"D":10,"E":12,"F":12,"MYSECONDSTRUCT":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}}},"key":"E"}]
Find all matches for a nested struct value
myStruct = {
A : 2,
B : 4,
C : 8,
D : 10,
E : 12,
F : 12
};
myStruct.MYSECONDSTRUCT = {
A1 : 50,
A2 : 12
};
myStruct.MYSECONDSTRUCT.MYTHIRDSTRUCT = {
B1 : 12,
B2 : 65
};
myValue = StructFindValue( myStruct, "12", "all" );
WriteOutput( JSONSerialize( myValue ) );
Result: [{"path":".E","owner":{"A":2,"B":4,"C":8,"D":10,"E":12,"F":12,"MYSECONDSTRUCT":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}}},"key":"E"},{"path":".F","owner":{"A":2,"B":4,"C":8,"D":10,"E":12,"F":12,"MYSECONDSTRUCT":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}}},"key":"F"},{"path":".MYSECONDSTRUCT.A2","owner":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}},"key":"A2"},{"path":".MYSECONDSTRUCT.MYTHIRDSTRUCT.B1","owner":{"B2":65,"B1":12},"key":"B1"}]
Find first match for a nested struct value using member function
CF11+ calling the findValue member function on a struct.
myStruct = {
A : 2,
B : 4,
C : 8,
D : 10,
E : 12,
F : 12
};
myStruct.MYSECONDSTRUCT = {
A1 : 50,
A2 : 12
};
myStruct.MYSECONDSTRUCT.MYTHIRDSTRUCT = {
B1 : 12,
B2 : 65
};
myValue = myStruct.findValue( "12", "one" );
WriteOutput( JSONSerialize( myValue ) );
Result: [{"path":".E","owner":{"A":2,"B":4,"C":8,"D":10,"E":12,"F":12,"MYSECONDSTRUCT":{"A1":50,"A2":12,"MYTHIRDSTRUCT":{"B2":65,"B1":12}}},"key":"E"}]
Additional Examples
animals = {
COW : {
NOISE : "moo",
SIZE : "large"
},
PIG : {
NOISE : "oink",
SIZE : "medium"
},
CAT : {
NOISE : "meow",
SIZE : "small"
}
};
// Show all animals
Dump( label="All animals", var=animals );
// Find animal containing value of 'medium'
findMediumAnimal = StructFindValue( animals, "medium" );
// Show results in findMediumAnimal
Dump( label="Results of StructFindValue(animals, ""medium"")", var=findMediumAnimal );
Related
Last updated
Was this helpful?