How to filter and sort by dynamically created fields in grid?

I am creating a form in a job using

Form form;

FormRun formRun;

FormBuildDesign formBuildDesign;

FormBuildDataSource formBuildDataSource;

form = new Form();.

formBuildDataSource = form.addDataSource(“Table”);

formBuildDesign = form.addDesign(“Design”);



I am adding a grid to the form by

formBuildGridControl = formBuildDesign.addControl(FormControlType::Grid,“Table Grid”);

and than fields (they are named F1, F2, …) to this grid by

for(ii = 1; ii < 5; ii++)


formBuildGridControl.addDataField(,fieldName2Id(tableName2id(“Table”), strFmt(“F%1”,ii)));


Form is created, grid is added and visible but when I try to sort by a field I get

Invalid sort field type.

and I do not see filter function.

What I need to do to have sorting and filtering available?

I can’t reproduce your problem.

Can you tell me whether following code works in your system?

Form                    form = new Form();    
FormBuildDesign         design = form.addDesign("Design");
FormBuildDataSource     buildDs = form.addDataSource("CustTable");
FormBuildGridControl    grid = design.addControl(FormControlType::Grid, "Grid");
Args                    args = new Args();
FormDataSource          ds;
FormRun                 formRun;    

grid.addDataField(, fieldNum(CustTable, AccountNum));
formRun = classfactory.formRunClass(args);;
ds = formRun.dataSource(1);
ds.queryBuildDataSource().addSortField(fieldNum(CustTable, AccountNum), SortOrder::Descending);

By the way, if you post code that can be copied to AX and run without extra work, you’ll have a better chance that somebody will bother.

The fields has a type String with size Memo. With limited length everything works correctly.

Ah, that’s by design.

You should have debug static design first - if you debug too many things at once, you easily miss where the problem lies.

I hope that my code helped you at least a little; I would hate to hear that I just wasted my time. :slight_smile:

It help me but with different tasks :slight_smile: