Hi
Based on the requirement you have described, it looks to me like you have over complicated the query. Distilling you described requirement, you want to display all non-Confidential records plus all records created by the current user. So I would have written the x++ select like this...
while select caseDetailBase1 join caseCategoryHierarchyDetailloc where caseDetailBase1.CategoryRecId == caseCategoryHierarchyDetailloc.RecId && (caseCategoryHierarchyDetailloc.LegalConfidential == NoYes::No || caseDetailBase1.createdBy == curUserId())
You could implement that with a UNION query (one part returning all non-Confidential records and the other returning all Confidential records created by the current user but that's probably not the most efficient way as, I think, there is a way to directly implement the X++ code above using a single query.
I'd look at implementing this with a complex query range - these can be tricky to get right as the syntax required is very precise but its worth persevering with. Have a look at this blog to get to grips with the approach...
community.dynamics.com/.../how-to-use-complex-query-ranges-in-dynamics-ax