Reading Project Test Results - LogItems Readable in Iteration but not Recursion
- 6 years ago
A solution to this literally came to me in a dream, and it actually works!
There were a few basic syntax errors I should have caught just by looking at it, like not using the "var" keyword, and initializing an array incorrectly. I was also using the .concat() function to combine recursive results, but it clearly doesn't work the way I imagined it did. With that fixed, it does work a little better, but it's still not actually doing the thing I want it to do.
Now for my dream. I awoke with a start at 2 am this morning and realized suddenly that I'd forgotten to search for log items in the recursion method! This also involves removing the log item iteration from the main method, but I intended on doing that anyway, so it's a bonus.
Here's the corrected main code:
// Exporting the log function GetLogResults() { if(Project.Logs.LogItemsCount > 0) { // Exporting the test log contents try { // note that iteration is only done after the recursive // search method is called and its array returned var arr = FindTestLog(Project.Logs); Log.Message("Logs found: " + arr.length); for(var i = 0; i < arr.length; i++) { Log.Message("Test Log " + i + "exists!", ChildRead(arr[i])); } } finally { Log.Message("Goodbye!"); } } else Log.Message("No logs for export."); }
And the fixed recursive function:
function FindTestLog(Child) { var arr = []; var i, j; var name = ""; if(Child.Scheme != null) { name = Child.Scheme.Name; } // adds object to array if its name == "Test Log" if(Child.Scheme != null && aqString.Compare(Child.Scheme.Name, "Test Log", false) == 0) { arr.push(Child); } // if not, search children/data/rows/etc. for more objects and re-call // concatenating any returned arrays else { for(i = 0; i < Child.ChildCount; i++) { res = FindTestLog(Child.Child(i)); for(j = 0; j < res.length; j++) { arr.push(res[j]); } } for(i = 0; i < Child.DataCount; i++) { res = FindTestLog(Child.Data(i)); for(j = 0; j < res.length; j++) { arr.push(res[j]); } } for(i = 0; i < Child.RowCount; i++) { res = FindTestLog(Child.Rows(i)); for(j = 0; j < res.length; j++) { arr.push(res[j]); } } for(i = 0; i < Child.ChildRowCount; i++) { res = FindTestLog(Child.ChildRow(i)); for(j = 0; j < res.length; j++) { arr.push(res[j]); } } for(i = 0; i < Child.ColumnCount; i++) { res = FindTestLog(Child.ChildDataByIndex(i)); for(j = 0; j < res.length; j++) { arr.push(res[j]); } } for(i = 0; i < Child.LogItemsCount; i++) { res = FindTestLog(Child.LogItem(i)); for(j = 0; j < res.length; j++) { arr.push(res[j]); } } } return arr; }
A few of those search cases are probably unnecessary, but I wanted to get it at least working as intended before I futzed with efficiency.
Anyway... Solved! No thanks to you lot! hehehe