web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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)
  • Guruprasanna Profile Picture
    1,089 on at

    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();

                 }

    }

  • Nishi Gupta Profile Picture
    206 on at

    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?

  • Suggested answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    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()) { ... }

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans