// Convert Query to List. All work is done on this 'worklist' which is assigned to the request structure as well. Items = ValueList(Attributes.Query.ItemID); Parents = ValueList(Attributes.Query.ParentItemID); // Set Local Query Local = QueryNew(Attributes.Query.ColumnList); Current = 0; Path = 0; // Loop over Query list and order in a tree FOR(index=1;index LTE Attributes.Query.RecordCount;index=index+1) { //Adds a new row QueryAddRow(Local); //Sets the new row to the value for the list Position = ListFind(Parents, Current); //If the current ID has no children, drop down the path and try again WHILE(NOT Position) { Path = ListRest(Path); Current = ListFirst(Path); Position = ListFind(Parents, Current); } FOR(i=1;i LTE listlen(Attributes.Query.Columnlist);i=i+1) { Column = listgetat(Attributes.Query.Columnlist, i); QuerySetCell(Local, Column, Evaluate('Attributes.Query.'&Column&'[Position]')); } Current = ListGetAt(Items, Position); Parents = ListSetAt(Parents, Position, '-'); Path = ListPrepend(Path, Current); } // I hate using left hand pound signs. It 'breaks' the rules. SetVariable('Caller.'&Attributes.ReturnVar, Local);