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

Notifications

Announcements

No record found.

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,160 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,160 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans