How to update multiple rows at backend and refresh the UI?

Hi,

I am new to AX.

I have a grid, which displays data from multiple companies, each company has multip rows. each row has a flag (yes or no).

What I am trying to do is:

when user select one row and click a button “flag all rows of the same company”, all rows from the same company should have flags set to “yes”

What I have done is:

in the click event of the button, I updated all rows using update_recordset statement.

The problem I have is:

Althought the data in the SQL DB is updated, but he UI (the grid control) is not refreshed

This should be very simple, could anyone help me?

Thanks!

Just put this code in the clicked method (after the update_recordset statement)

_ds.reread();

_ds.research();

Where is the name of the datasource of the table you update.

Hi,

That works for most of the part.

The only thing still broken is:

After *_ds.research(), the current selected row is changed to the first row.

Do you know how to keep the current selected row?

Thanks!

In order to keep the current record selected in AX 2009 you should use research(true).

On older versions, you should call _ds.findRecord() after research().

Hi Velislav,

Thanks a lot for your help!

I tried “research(true)”, it doesn’t compile, so I guess I am using an older version of the Dynamics AX.

About using “findRecord()”, it need to take one input parameter, which I believe is the reference to the record I want to select.

Do you know how to get the reference of the currenlt selected record so I can pass into “findRecord()”?

Thanks again!

You can get the currently selected record with the _ds.cursor() function on you datasource.

Hi Velislav,

I tried that but didn’t make it work.

I included the code below, do you see anything wrong?

void clicked()
{
MyTable myTable;
MyTable currentRecord;
;

currentRecord=MyTable_ds.cursor();

update_recordset myTable
setting myFlag = NoYes::Yes
where myTable.companyName==currentCompanyName;

MyTable_ds.reread();
MyTable_ds.research();
MyTable_ds.findRecord(currentRecord);

super();
}

void clicked()
{
MyTable myTable;
MyTable currentRecord;

MyTableId myTableId;
;

currentRecord = MyTable_ds.cursor();
myTableId = currentRecord.MyTableId;

update_recordset myTable
setting myFlag = NoYes::Yes
where myTable.companyName==currentCompanyName;

MyTable_ds.reread();
MyTable_ds.research();
//MyTable_ds.findRecord(currentRecord);
MyTable_ds.findValue(fieldNum(MyTable, MyTableId), MyTableId);

super();
}

It worked!

Thanks a lot Velislav!

You are the best!

Thanks. LOL.