web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to set fields value in every line of a grid through x++?

(0) ShareShare
ReportReport
Posted on by 75

I want to set the field value of the grid which is related to the data source. I use the datasource_ds.getFirst() and datasource_ds.getNext to retrieve all of the records, and then set the value of each field. After the loop, I use datasource_ds.refreshEx(-1) to refresh the grid, but only the first line is changed.

My code is as below:

SalesLine salesLine;

salesLine = SalesLine_ds.getFirst();
while (salesLine)
{
    salesLine.QtyOrdered = 20;
    salesLine = SalesLine_ds.getNext(); 
}
SalesLine_ds.refreshEx(-1);

How can I set value of all lines? 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Rustem Galiamov Profile Picture
    8,072 on at

    Hi bjdchw!

    This method works only with selected rows. If you want to update all rows in the grid without selecting you should use queryRun of ds query.

        QueryRun    qr = new QueryRun(SalesLine_ds.query());
        SalesLine   salesLineLocal;
        
        ttsBegin;
        while (qr.next())
        {
            salesLineLocal = qr.get(tableNum(SalesLine));
            salesLineLocal.selectForUpdate(true);
            salesLineLocal.QtyOrdered = 20; 
            salesLineLocal.update();
        }
        ttsCommit;
        
        SalesLine_ds.executeQuery();


  • bjdchw Profile Picture
    75 on at

    Hi Rustem Galiamov,

    Thank you for your reply. I only want to update all the value in the screen. It means I don't want to save the new value to the table right now. Do you have any ideas?

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    Hmm. What do you mean "I don't want to save the new value to the table right now" ?

    The rows what you may see on the grid, it's a current query of DS. You can add ranges, filters and use query as well.

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    The record in the grid is saved when focus is removed from that line. So you can't assign values to multiple lines without saving.

    If you share your business requirement, maybe we can help you find another solution.

  • bjdchw Profile Picture
    75 on at

    My business requirement is that update the grid in a button event, but not save to db until click the save button.

    Maybe tempDB is a good solution.

  • Verified answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    In this case a temp table is a good solution. You will first save the values in your temp table, and when the user clicks Save, the values will be written in the actual table.

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    And another fields must be changed also. LineAmount as example. Just keep it in mind...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans