Hoiw获取查询的选择字段

时间:2015-06-12 19:29:23

标签: axapta x++ dynamics-ax-2012

我需要动态指定任何AOT查询,然后回读列和值。

我非常接近。唯一的问题是它列出了每个数据源中的所有字段,而不仅仅是指定的字段,以便在查询中返回值。

有什么建议我如何才能返回查询结果字段,而不是返回数据源中的所有列?

谢谢,

  • 布拉德

            while (queryRun.next())
            {
                //parse through each datasource
                for(i = 1; i <= workingQuery.dataSourceCount(); i++)
                {
                    //get all fields in this data source
                    qbfl = workingQuery.dataSourceNo(i).fields();
                    cnt = qbfl.fieldCount();  //this comes up with the correct number, so AX is aware of the right number
    
                    //DID NOT WORK EITHER common = workingQuery.dataSourceNo(i).getNo();
                    common = queryRun.get(workingQuery.dataSourceNo(i).table());
                    dicttable = new DictTable(common.TableId);
                    fieldcnt   = dicttable.fieldCnt();
                    //parse through the fields and set the values in the new table
                    for (i = 1; i <= fieldcnt; i++)
                    {
                        //write the field names and values
                        fieldid   = dicttable.fieldCnt2Id(i);
                        dictfield = new dictfield(common.TableId,fieldid);
                        info(dicttable.fieldName(fieldid));
                        info(common.(dictfield.id()));                            
                    }
                }
            }
    

1 个答案:

答案 0 :(得分:1)

您需要使用fieldCountfield方法迭代系统类QueryBuildFieldList。另请查看Axaptapedia

Query q = new Query(queryStr(CustTable));
QueryBuildDataSource qbds = q.dataSourceTable(tableNum(CustTable));
QueryBuildFieldList qbfl = qbds.fields();
Counter i;
for (i = 1; i <= qbfl.fieldCount(); i++)
    info(new DictField(qbds.table(), qbfl.field(i)).name());