在 GlideAggrigate 中通过 dot walk 为 groupBy 获取空值

Getting empty value with dot walk for groupBy in GlideAggrigate

在下面的例子中,我需要获取类名的值。我得到空值。让我知道我错过了什么。我需要为每种类型找到所有不同的 类。

var ga_type = new GlideAggregate('cmdb_rel_ci');
ga_type.groupBy('type');
ga_type.query();

if(ga_type.next()){
    gs.log("Type : " + ga_type.type.getValue());

    var ga_parent = new GlideAggregate('cmdb_rel_ci');
    ga_parent.addQuery('type.sys_id', ga_type.type.getValue());
    ga_parent.groupBy('parent.sys_class_name');
    ga_parent.query();

    var parent = [];
    while(ga_parent.next()){
        var p = {};
        p.parentClassName = ga_parent.parent.sys_class_name.toString();
        p.parentName = ga_parent.parent.name.toString();
        gs.log("ParentClassName : " + p.parentClassName + " Parent Name : " + p.parentName);
        parent.push(p);
    }
}

正如 Tim 所说,很难确切地知道这里要问什么,但看起来您可能正在尝试获取 cmdb_rel_ci 中所有类型关系的列表。如果是这样的话,应该这样做:

var count = new GlideAggregate('cmdb_rel_ci');
count.addAggregate('COUNT', 'type');
count.query();

var listOfParents = [];

while(count.next()){
    var parent = count.type;
    var parentCount = count.getAggregate('COUNT','type');
    listOfParents.push(parent); //or parent.getDisplayValue()
    gs.log(parent.getDisplayValue() + ": " + parentCount);
}

这基本上只是文档中的第三个示例:GlideAggregate