I am attempting to use structFindKey to create an "org" struct from a query.
I am starting with a query that looks like this.
from this I am trying to build a struct that represents the actual org structure that I would like to look something like this:
I am starting with my request.hierarchyStruct
that looks like this:
here is the code so far
for(row in getCorpUserHierarchy){
insertIntoHierachy(row);
}
function insertIntoHierachy(thisRow){
var thisKey = thisRow.parentGroupId;
var newChild = {
"level" = thisRow.ThisLevel
, "levelName" = thisRow.levelName
, "groupName" = thisRow.groupName
, "members" = []
};
keyResult = structFindKey(request.hierarchyStruct, thisKey, "one");
if(arrayLen(keyResult) > 0){
writeDump(keyResult);
newPath = 'request.hierarchyStruct' & keyResult[1].path;
foundKey = structGet(newPath);
foundKey[thisRow.groupId] = newChild;
}
}
I am able to "find the key" which dumps the key result:
But when the first row "Jasmines Region" finds and try to add the "newChild" to it I get an error
I have tried a variety of combinations with the path including
var newPath = keyResult[1].path;
var fullPath = 'request.hierarchyStruct'
var pathArray = listToArray(newPath,'.');
for(i in pathArray){
fullPath = fullpath & "." & i ;
}
I don't know if it matters a lot but I am using the lastest version of LUCEE not adobe's coldfusion.
This is the first time using structFindKey
and it's path
can anyone shed any light on this???
You may have stumbled upon a bug in Lucee. Your code seems to work with Adobe ColdFusion. I created a gist on TryCF showing this.
<cfscript>
hierarchyStruct = {};
hierarchyStruct.0 = {
"groupName" = "top level"
, "level" = "1"
, "levelName" = "region"
};
writeDump(hierarchyStruct);
keyResult = structFindKey(hierarchyStruct, "0", "one");
writeDump(keyResult);
newPath = 'hierarchyStruct' & keyResult[1].path;
writeDump(newPath);
foundKey = structGet(newPath);
writeDump(foundKey);
</cfscript>
That gist is using Adobe ColdFusion 11 and it will run. Change the engine to Lucee and it will error.
You can get around this error by changing the name of the request.hierarchyStruct.0
structure. Note that it is failing on that structure being named 0
.
For example, I created another gist changing the name of that structure to a0
and it works using Lucee.
<cfscript>
hierarchyStruct = {};
hierarchyStruct.a0 = {
"groupName" = "top level"
, "level" = "1"
, "levelName" = "region"
};
writeDump(hierarchyStruct);
keyResult = structFindKey(hierarchyStruct, "a0", "one");
writeDump(keyResult);
newPath = 'hierarchyStruct' & keyResult[1].path;
writeDump(newPath);
foundKey = structGet(newPath);
writeDump(foundKey);
</cfscript>