Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Retrieving selected row in the grid in Form when form control button is clicked.

Posted on by 1,643

Hi,

I added new button “Back to draft” in the Approval menu in the Journal. Basically what it has to do it when the user click that button, the journal which is already reported as ready should be reverted back so that user can amend the journal.

The problem I am having now is I am not being able to figure out the way to retrieve the selected row in the journal.

  /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(LedgerJournalTable, BackToDraft2), FormControlEventType::Clicked)]
    public static void BackToDraft2_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        FormRun                         formrun = sender.
        Object                          LedgerJournalTable_DS = FormRun.dataSource(formDataSourceStr(LedgerJournalTable,LedgerJournalTable));
        LedgerJournalTable              localLedgerJournalTable =   LedgerJournalTable_DS.getFirst() as LedgerJournalTable;
        localLedgerJournalTable.ReportedAsReadyBy = '';
        LedgerJournalTable_DS.research();
    }

0511.Capture.PNG

Here is the code which just retrieves the first row in the data source but I need to retrieve the selected row in the grid so that I can change the status for that particular record. How would I do that using event handling? 

Thank you,

*This post is locked for comments

  • Tony Mok Profile Picture
    Tony Mok 577 on at
    RE: Retrieving selected row in the grid in Form when form control button is clicked.

    I know that the question is almost a year ago, but I want to share my solution for the programmer who is looking for.

    LedgerJournalTable ledgerJournalTable;
    
    FormDataSource LedgerJournalTable_DS = sender.formRun().dataSource("LedgerJournalTable");
    
    ledgerJournalTable = LedgerJournalTable_DS.cursor();


  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Retrieving selected row in the grid in Form when form control button is clicked.

    Why don't you simply use a menu item button and receive the record in args.record() as usual?

    If you insist on your design, try something like sender.dataSourceObject().cursor().

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!

Community AMA December 12th

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans