web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at
    RE: How to set fields value in every line of a grid through x++?

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

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to set fields value in every line of a grid through x++?

    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.

  • bjdchw Profile Picture
    75 on at
    RE: How to set fields value in every line of a grid through x++?

    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.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to set fields value in every line of a grid through x++?

    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.

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at
    RE: How to set fields value in every line of a grid through x++?

    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.

  • bjdchw Profile Picture
    75 on at
    RE: How to set fields value in every line of a grid through x++?

    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?

  • Verified answer
    Rustem Galiamov Profile Picture
    8,072 on at
    RE: How to set fields value in every line of a grid through x++?

    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();


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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans