Query sorting by string field

Hi all, I am trying to sort a query(VendTrans) by a string field(PostingProfile) , without success. Are there any limitations? I can sort by other fields like Accountnum,TransDate etc. Here is my code:

public boolean fetch() { boolean ret = true; boolean devir = true; Query qr,qr2; QueryRun qrr,qrr2; QueryBuildDataSource qbds,qbds2; Boolean empty; Boolean printed; boolean first = true ; boolean postingPrinted; VendPostingProfile old; VendTrans vendTransSum; int i; ; element.design().caption(element.design().caption()+" " + date2str(startDate,123,2,2,2,2,4) + " - " + date2str(endDate,123,2,2,2,2,4)); qr = new Query(this.query()); qbds = qr.dataSourceTable(tablenum(VendTable)); SysQuery::findOrCreateRange(qr.dataSourceTable(tablenum(VendTrans)),fieldnum(VendTrans,TransDate)).value(SysQuery::range(datenull(),endDate)); qbds.relations(true); if (groupByPostingProfile)////////////// { qbds.addSortField(fieldnum(VendTrans,PostingProfile),Sortorder::Ascending); qbds.addSortField(fieldnum(VendTable,AccountNum),Sortorder::Ascending); qbds.addSortField(fieldnum(VendTrans,TransDate),Sortorder::Ascending); } else { qbds.addSortField(fieldnum(VendTable,AccountNum),SortOrder::Ascending); qbds.addSortField(fieldnum(VendTrans,TransDate),Sortorder::Ascending); qbds.addSortField(fieldnum(VendTrans,PostingProfile),Sortorder::Ascending); } qrr = new QueryRun(qr); while(qrr.next()) { vendTrans = qrr.get(tablenum(VendTrans)); // postingPrinted = false; if(old != vendTrans.PostingProfile) if (groupByPostingProfile && element.checkPostingProfileRecExists(vendTrans.PostingProfile)) { ProgrammableSectionPostingProfile.executeSection(); element.send(vendTable); ProgrammableSectionVendTrans.executeColumnHeadings(); if(first) { first = false; } else { ProgrammableSectionClosings.executeSection(); } element.setOpeningBalanceAfterPrint(); } old = vendTrans.PostingProfile; if (qrr.changed(TableNum(VendTable))) { vendTable = qrr.get(TableNum(VendTable)); empty = false; printed = false; devir = true; if (dontPrintEmpty) { select sum(AmountMST) from vendTransSum where vendTransSum.AccountNum == vendTable.AccountNum && vendTransSum.TransDate <= endDate && ( !groupByPostingProfile || (groupByPostingProfile && vendTransSum.PostingProfile == vendLedger.PostingProfile)); if (!vendTransSum.AmountMST) empty = true; } if (empty) continue; printed = true; vendTable = qrr.get(TableNum(VendTable)); if(first) { first = false; } else { ProgrammableSectionClosings.executeSection(); } element.send(vendTable); ProgrammableSectionVendTrans.executeColumnHeadings(); element.setOpeningBalanceAfterPrint(); } if(vendTrans.TransDate < startdate) { element.calcAmounts(); } else { if(devir) { transDate = startDate; amountCredit =amountCreditTotal; amountDebit = amountDebitTotal; ProgrammableSectionTotal.executeSection(); devir = false; }///devir bakiyesi if (qrr.changed(Tablenum(VendTrans))) { if (empty) continue; vendTrans = qrr.get(tablenum(VendTrans)); if(vendTrans.TransDate >= startDate)///SA { select firstonly ledgerTrans where ledgerTrans.Voucher == vendTrans.Voucher; transDate = vendTrans.TransDate; element.send(vendTrans); element.send(ledgerTrans); element.calcAmounts(); lastAccountNum = vendTrans.AccountNum; ProgrammableSectionVendTrans.executeSection(); } } }//else transDate = endDate; } if (printed && !empty) ProgrammableSectionClosings.executeSection(); return ret; }

Any suggestions?

No, there is no such limitation. Why do you think that it does work?

Look at this example:

Query q = new Query();
QueryBuildDataSource ds = q.addDataSource(tableNum(VendTrans));
ds.addSortField(fieldNum(VendTrans, PostingProfile));
info(ds.toString());

It returns the following query string: SELECT FIRSTFAST * FROM VendTrans ORDER BY VendTrans.PostingProfile ASC.

Check the query string generated from your query.