Alex Pereira
Alex Pereira

Reputation: 170

Multi-clause AND query not working when there are more than two AND clauses

I created a custom app for my company, and the query works fine as long as there are only two fields in it, once a third one is added, it returns no records:

For reference, I am querying STORIES and DEFECTS:

    var query = [];
var queryCriteria = buildQueryFilter(STORIES);
query[0] = {
    key   : STORIES,
    type  : "HierarchicalRequirement",
    fetch : "FormattedID,Name,Owner,SubProject,CreationDate,Release,Iteration,ScheduleState,State,Build,Parent",
    order : "FormattedID",
    query : queryCriteria
};

var queryCriteria = buildQueryFilter(DEFECTS);
if (!(showUserStoriesOnly)){
    query[1] = {
        key   : DEFECTS,
        type  : "defects",
        fetch : "FormattedID,Name,Owner,SubProject,CreationDate,Release,Iteration,ScheduleState,State,FixedInBuild,Requirement",
        order : "FormattedID",
        query : queryCriteria
    };
}

rallyDataSource.findAll(query, showResults);

EDIT: Here is some "abbreviated" code for the buildQueryFilter:

returnFilter += returnFilter.length === 0 ? '' : ' AND '
returnFilter += '(Iteration.Name = "' + filterIteration + '")';

returnFilter += returnFilter.length === 0 ? '' : ' AND '
returnFilter += '(ScheduleState = "' + filterScheduleState + '")';

returnFilter += returnFilter.length === 0 ? '' : ' AND '
returnFilter += '(Owner = \"__USER_NAME__\")';


returnFilter = '(' + returnFilter + ')';                        

When the "queryCriteria" is:

Query (stories):((Iteration.Name = "25 (10/02 - 10/16)") AND (ScheduleState = "Accepted"))

Query (defects):((Iteration.Name = "25 (10/02 - 10/16)") AND (ScheduleState = "Accepted"))

It works. But once I add a 3rd field - and it does not matter what field, or what order - then it does not work anymore:

Query (stories):((Iteration.Name = "25 (10/02 - 10/16)") AND (ScheduleState = "Accepted") AND (Owner = "[email protected]"))

Query (defects):((Iteration.Name = "25 (10/02 - 10/16)") AND (ScheduleState = "Accepted") AND (Owner = "[email protected]"))

I've been looking over the documentation and this is supposed to work. I am not sure why it is not. Does anyone have a clue?

Thanks!

Upvotes: 2

Views: 290

Answers (1)

Kyle Morse
Kyle Morse

Reputation: 8410

Using the rally.sdk.util.Query utility should help you build valid queries (the syntax can get pretty hard to read with all the nested () in large queries).

var queries = [
    'Iteration.Name = "' + filterIteration + '"',
    'ScheduleState = "' + filterScheduleState + '",
    'Owner = "__USER_NAME__"'
];
var queryFilter = rally.sdk.util.Query.and(queries);
var queryString = queryFilter.toString();

//queryString should be this:
//(((Iteration.Name = "25 (10/02 - 10/16)") AND (ScheduleState = "Accepted")) AND (Owner = "[email protected]"))

Upvotes: 2

Related Questions