FormDataSource positionToRecord doesn't work

I am trying to load a record into a formDataSource by code using the positionToRecord function and it doesn’t work. I have a text field where the user inputs a value and on the modified method of that field, I am trying to position the record. There is no grid on the form, just fields for input. After the value is entered in the field, and the modified method is called, the formDataSource doesn’t change. When I step through it I can see that the FigureRec record is populated. What am I missing here to get the formDataSource record to change?

        public boolean modified()
        {
            boolean ret;
            FigureTbl  FigureRec;
        
            ret        = super();
            FigureRec  = FigureTbl::Find(this.valueStr());
            if (FigureRec)
            {
               FigureTbl_ds.positionToRecord(FigureRec);
            }
            return ret;
        }

Regards,

Shawn

What’s the point of using positionToRecord() if you have no grid? Could you explain what you’re trying to achieve?

By the way, here is a trivial example demonstrating that positionToRecord() works:

class TestPosition
{
    [FormEventHandler(formStr(CustGroup), FormEventType::PostRun)]
    public static void CustGroup_OnPostRun(xFormRun _sender, FormEventArgs _e)
    {
        _sender.dataSource().positionToRecord(CustGroup::find("A group ID"));
    }
}

Thank you for the reply Martin. The form I am working with has multiple fields each tied to a record in the datasource. The field I am doing the lookup on is the primary number key of the datasource and is a number sequence. When the user selects a record in this lookup, I want to load that record to allow the user to edit the rest of the fields. I have tried to do it with just a string edit control not tied to the formdatasource and attempted to load the record when the field was modified, but nothing changes. Is the positionToRecord only effective with grids?

Shawn

Binding the field to a data source is wrong. It would mean changing the field, not defining a filter. Also, the field should be set as read-only.

Use an unbound field for the filter and bind the other fields to the data source. When changing the filter control (= in modified() method), apply a filter to your data source:

QueryBuildRange range = SysQuery::findOrCreateRange(myTable_ds.queryBuildDataSource(), fieldNum(MyTable, MyField));
range.value(queryValue.text());

and execute the query:

myTable_ds.executeQuery();

Thank you for all your help Martin. Your suggestion worked and took care of the issue.

Shawn