Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Get list of selected record from current query

Posted on by 115

Hello,

I want to get all selected (checked) lignes from this tableinevtn.PNG

Actualy, i get only the last checked (selected) value of my table like this:

"InventQuarantineOrder.Recid"

Can you  tell me how can get all recids of selectection lignes.

Thinks.

*This post is locked for comments

  • nach68 Profile Picture
    nach68 115 on at
    RE: Get list of selected record from current query

    Rectification  in second snippet (Martin Drab)

    Add "True":

    InventCurrent = InventQuarantineOrder_ds.getFirst(True); // to get selected records

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Get list of selected record from current query

    Does your second snippet really works? I think it'll return all records, not marked records as required. Also, if you look at the code linked by Vilmos (and in MultiSelectionHelper.getFirst()), you'll see that that there are two cases depending on whether getFirst(true) returns true or not. That's another piece missing in your code.

    That's why you should use MultiSelectionHelper - you won't make such mistakes. Remember that the best code is the one that you don't have to write, test and maintain.

  • Verified answer
    nach68 Profile Picture
    nach68 115 on at
    RE: Get list of selected record from current query

    Thanks for your help, I tried both methods and I cooked up a snippet of code for each one of them:

    Ex with Class MultiSelectionHelper :

    {

    //

    MultiSelectionHelper Msh;

    InventQuarantineOrder InventCurrent;

    //Init Msh

    Msh = MultiSelectionHelper::construct();

    //set Data source

    Msh.parmDatasource(InventQuarantineOrder_ds);

    InventCurrent = Msh.getFirst();

    While(InventCurrent)

    {

    info(int2str(InventCurrent.RecId));

    InventCurrent =Msh.getNext();

    }

    }

    Ex 2 with GetNext(), GetFirst() of data source :

    {

    InventQuarantineOrder InventCurrent;

    //set Data source

    InventCurrent =InventQuarantineOrder_ds.getFirst();

    While(InventCurrent)

    {

    info(int2str(InventCurrent.RecId));

    InventCurrent = InventQuarantineOrder_ds.getNext();

    }

    }

    Happy Testing :)

     

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Get list of selected record from current query

    I strongly recommend using MultiSelectionHelper. Writing the whole thing manually is more work, is easier to do it wrong, it's harder to read and so on.

  • Verified answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Get list of selected record from current query

    If you want to iterate through marked records in a form datasource, this is how you'd do it:

    [View:https://community.dynamics.com/ax/b/dynamicsnavax/archive/2012/01/18/loop-through-record-from-data-source-ax-2012:750:50]

    Refer to the mark flag within the documentation:

    [View:https://msdn.microsoft.com/en-us/library/formdatasource.getfirst.aspx:750:50]

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Get list of selected record from current query

    AX contains the MultiSelectionHelper class for this purpose.

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans