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)

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

(0) ShareShare
ReportReport
Posted on by 1,645

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

I have the same question (0)
  • Tony Mok Profile Picture
    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
    235,914 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

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
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans