Hoiw to get the selection fields of a query

5.1k views Asked by At

I need to dynamically specify any AOT query, then read back the columns and values.

I am pretty close. The only problem is that it lists ALL fields in each datasource instead of just the fields specified to return values in the query.

Any suggestions how I can get this to return query result fields only, instead of all columns in the datasource?

Thanks,

  • Brad

            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

There are 1 answers

0
Jan B. Kjeldsen On

You need to iterate the system class QueryBuildFieldList using fieldCount and fieldmethods. Also check 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());