当有两个以上的AND子句时,多子句和查询不起作用

时间:2012-10-23 13:18:13

标签: rally

我为我的公司创建了一个自定义应用,只要其中只有两个字段,查询就可以正常工作,一旦添加了第三个字段,它就不会返回任何记录:

作为参考,我正在查询故事和缺陷:

    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);

编辑:这是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 + ')';                        

当“queryCriteria”为:

查询(故事):((Iteration.Name =“25(10/02 - 10/16)”)AND(ScheduleState =“Accepted”))

查询(缺陷):((Iteration.Name =“25(10/02 - 10/16)”)AND(ScheduleState =“Accepted”))

有效。但是,一旦我添加 3rd 字段 - 并且无论哪个字段或什么顺序无关紧要 - 那么它就不再起作用了:

查询(故事):((Iteration.Name =“25(10/02 - 10/16)”)AND(ScheduleState =“Accepted”)AND(Owner =“user @ domain” .COM“))

查询(缺陷):((Iteration.Name =“25(10/02 - 10/16)”)AND(ScheduleState =“Accepted”)AND(Owner =“user @ domain” .COM“))

我一直在查看文档,这应该可行。我不知道为什么不是。有没有人有线索?

谢谢!

1 个答案:

答案 0 :(得分:2)

使用rally.sdk.util.Query实用程序可以帮助您构建有效的查询(在大型查询中,所有嵌套()的语法都很难阅读。)

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 = "user@domain.com"))