Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Update check box field in grid

Posted on by Microsoft Employee

Hi guys, I am trying to update a check box field in my grid by using a button clicked method.

How should I do it?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update check box field in grid

    Thank you Leandro, This is the answer I need.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update check box field in grid

    Hi,

    I guess the problem is in markAllLoadedRecords(). It seems records in a grid are progressively loaded (retrieved from database) as you scroll it.

    Instead of markAllLoadedRecords, try this:

    <Table>   record;

    for (record = <dataSource>_ds.getFirst(); record; record = <dataSource>_ds.getNext())

    {

       ...

    }

    <dataSource>_ds.research(true);

    If your code isn't dependant on filters set on the datasource, You can update the table directly with a while select forupdate.

    You could also retrieve the query from <datasource>_ds.queryRun() and retrieve the records with it. This will work similarly to the code I posted above.

    Regards,

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update check box field in grid

    Hi Steeve,

    Below is my code:

    void clicked()

    {

       int i;

       xinit_CustomerDet custdet;

       ;

       super();

       xinit_CustomerDet_ds.markAllLoadedRecords(1);

       custdet = xinit_CustomerDet_ds.getFirst(true);

       while (custdet)

       {

           custdet.Active = NoYes::Yes;

           custdet.write();

           custdet = xinit_CustomerDet_ds.getNext();

       }

       xinit_CustomerDet_ds.research(true);

    }

    I can updated the record but it did not updated all. In my grid, i have over 100 records, it always updated until half of it. And i have to click again button to trigger the function and update. Is there any solution to solve this?

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update check box field in grid

    In addition to Steeve's guidance, you can use <datasourcename>_ds.research() only once at the end of the process to update the display of all modified records.

    Regards,

  • Verified answer
    Steeve Gilbert Profile Picture
    Steeve Gilbert 1,501 on at
    RE: Update check box field in grid

    Use <datasourcename>_ds.getFirst() and <datasourcename>_ds.getNext() to browse the record.  Modify each record and call write() so save the change.  You will maybe need to call <datasourcename>_ds.refresh too see the change on the form.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update check box field in grid

    Hi Pvanstilpelen,

    I only can updated the first record. How about if I have 10 records in the grid view?

    I am using "<datasourcename>.<fieldname> = NoYes::Yes"  this code.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update check box field in grid

    If your checkbox is bound to a datafield you can put following code in your clicked method

    <datasourcename>.<fieldname> = NoYes::Yes

    If it is not bound to a datafield and the name of your checkbox column is for instance ValueChecked put following code in your clicked method on the button

    ValueChecked.Value(1);

    In the properties of the ValueChecked checkbox, set AutoDeclaration to YES to be able to use it in the coding.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,030 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans