Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

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

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

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 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
    nmaenpaa 101,156 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
    bjdchw 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
    nmaenpaa 101,156 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
    Rustem Galiamov 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
    bjdchw 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
    Rustem Galiamov 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans