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)

Fetch filtered data on class to export data on excel

(0) ShareShare
ReportReport
Posted on by 206

Hi all,

In a formA an "Export to Excel" button is added to export some particular fields  ,this button is connected to a menuiten MenuItemA(action) . The code to export is handled using a class ClassA. There can be 3 scenarios:

1. Without selecting any record the user clicks "Export to excel" - all the records are fetched in an excel sheet 

2. Selecting a few records the user clicks "Export to excel"- the selected records are fetched in an excel sheet( code done using form data source anymarked() method)

3. User filters data on one field (using ctrl+G ) and clicks "Export to excel"- the filtered records are to be fetched in an excel sheet.

How can we achieve this third scenario? (the rest 2 are done)

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    236,025 Most Valuable Professional on at
    RE: Fetch filtered data on class to export data on excel

    If you want to get all records returned by the current datasource query, simply take the query, create your own QueryRun instance and iterate records.

    It'll be something like this:

    QueryRun qr = new QueryRun(_args.record().dataSource().queryRun().query());
    while (qr.next()) { ... }
  • Nishi Gupta Profile Picture
    206 on at
    RE: Fetch filtered data on class to export data on excel

    Thanks guruprasanna ,

    this code will work if the filtering leads to one record .What if filtering leads to many records how can that be handled?

  • Guruprasanna Profile Picture
    1,078 on at
    RE: Fetch filtered data on class to export data on excel

    Hi Nisha,

    If i understood your question correctly.  When you filter the form using filter, using below code you can get all current data form grid using below code.

    In ClassA main method where your receive passing argument from form.

    public static void main(Args _args)

    {

                 FormDataSource        ds;

                 ds = FormDataUtil::getFormDataSource(_args.record());

                 YourTable = ds.getFirst(true) ? ds.getFirst(true) : ds.cursor();

                 while (YourTable)

                 {

                    // Business logic

                    YourTable = ds.getNext();

                 }

    }

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
Guy Terry Profile Picture

Guy Terry 2 Moderator

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans