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)

Pass data from data source into grid

(0) ShareShare
ReportReport
Posted on by

I have one Excel document, and I'm exporting and importing the data from it to a table. So that works ok, but now the data from that document has to be shown on grid. I have the class, the dialog that opens the document and writes the data on the table. 

How can I pass the data from that excel document (table) into the grid of the form?

Thank you in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    When you say it works ok, I assume you successfully imported data from spreadsheet onto Ax table. Please check the datasource property of your Grid, I think either it would be empty/points to some other table so please set the value equal to your table and re-open the form to see the data.

  • Community Member Profile Picture
    on at

    I did that, but when the form is opened I need the grid to  be empty. I did that with overriding the init method of the data source.

    Now I need one button on the form, and the question is how that button can populate the grid with the records from the table. I hope that my question is clear now.

    Thank you.

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Introduce a checkbox by name AvoidDisplay on your table, by default mark it to yes(during import). In the init method of your datasource, add a range on AvoidDisplay to yes such that you cannot see any data on opening the form(like below)

    QuerybuildDatasource qbds;

    QuerybuildRange qbr;

    super();

    qbds = this.query().datasourcetable(tablenum(YourTable))

    qbr = SysQuery::findorCreateRange(qbds, fieldNum(YourTable, AvoidDisplay));

    qbr.value(Queryvalue(NoYes::No));

    In the clicked method of your button, add code to set this value AvoidDisplay to "no" on all the table records(using update_Recordset operation) and make a call to executeQuery method like YourTable_ds.executeQuery() to see the data.

    Hope this helps you.

  • Community Member Profile Picture
    on at

    Thanks for your answer, but as I said I already did that, when the form is opened it doesn't show the data from the data source. I mentioned that to introduce you what I'm doing.

    Now my question is how to import the data from the data source on the grid with a button click.

    Form opens > Grid is empty => this is done.

    Button 'Show all' is clicked > the grid is displaying all the data => question.

    I have to mention, there are two grids on the form, so when the button is clicked i want the data to be shown on the first grid.

    Thank you again.

  • Suggested answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    If you are hiding data with some range on the datasource query when you open a form then you would have to modify the query when you click button show all as well . Make sure once you modify your query to show data call datasource_ds.executeQuery() method.

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    My understanding is that you are able to get the grid with blank data upon opening the form and you want to get the data on clicking a button.If so, in the clicked method of the button you need to clear the ranges either on the primary data source or on the relevant data source(of the second grid) through following statement

    To display data:

    void clicked()
    {
        QueryBuildDataSource qbds;
        
        super();
    
        qbds = this.query().dataSourceTable(tableNum(TableName));
        qbds.clearRanges(); // Clears ranges.
        TableName_ds.executeQuery(); // Displays the data, TableName_ds refers to the datasource of your required grid
    }
  • Community Member Profile Picture
    on at

    Dejana,

    While opening a form, if you want the grid to be empty (in case if you aren't filtering based on any values and just you don't want to display available data in Table), set the Grid's datasource AutoSearch property to No. Then in button's clicked(), follow Chaitanya's approach. You will get the desired output. 

    Please verify the answer if it helped you!!!

  • Community Member Profile Picture
    on at

    Im still not able to proceed with this, Im getting this error message

    2678.Untitled.png

  • Community Member Profile Picture
    on at

    This is ok, I fixed the error, but still the data doesnt show on the grid. I have a hint that refresh on the grid has to be done.. Any sugeestions

  • Community Member Profile Picture
    on at

    Another problem when I use the code above:

    QueryBuildDataSource object not initialized.

    Stack trace

    (C)\Forms\Nova\Designs\DesignList\SimpleButton\Methods\Clicked - line 7

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