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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Form created with X++ with multiple datasources shows only 1 record

(2) ShareShare
ReportReport
Posted on by 20
Hello,
I have created a form with multiple (dynamic) datasources, depending on the selected record on the main form. 
This form is created and is run clicking on a button on the main form. 
 
I am able to build the form with TabControl=FastTabs, and the different datasources collected. 
But in the second datasource only 1 of the 3 fetched records is shown. The QueryBuildDatasource.Firstonly() is set to false, 
I can see that all 3 records are fetched. it seems to be a mere display problem. 
 
Here is the entire code, can anybody help me with this? 
 
thx,
Ulli
 
    static void ShowStagingTableForMessage(CG_EDI_EDIMessageStatus _message)
    {
        Args args;
        Form form;
        FormRun formRun;
        FormBuildDesign formBuildDesign;
        FormBuildDataSource formBuildDataSource;
        FormBuildGridControl formBuildGridControl;
        FormBuildTabControl formBuildTabControl;
        FormBuildTabPageControl formBuildTabPageControl;
        FormStringControl formStringControl;
        FormGridControl formGridControl;
        FormDataSource formDataSource;
        DictTable dictTable;
        int idx = 0;
        CG_EDI_InterfaceSection interfaceSection;
        TableName       stagingTableName;
        CG_EDI_InterfaceSectionId sectionName;
        Map map;
        MapEnumerator mapEnum;
        QueryBuildDataSource    qbds;
        QueryBuildRange         qbr;
  
        map = new Map(Types::String, Types::String);
        // Create the form header.
        form = new Form();

        // Create the form design.
        formBuildDesign = form.addDesign("Design");
        formBuildDesign.caption("@CG_EDI_Label:MessageStagingTables");
        formBuildDesign.showDeleteButton(0);
        formBuildDesign.showNewButton(0);
        // Add tabbed page controls, a grid control, and string controls.
        formBuildTabControl = formBuildDesign.addControl(FormControlType::Tab, "Overview");
        formBuildTabControl.style(TabStyle::FastTabs);
        formBuildTabControl.arrangeMethod(FormArrangeMethod::Vertical);
        formBuildTabControl.heightMode(FormHeight::SizeToContent);
        //** Loop Interface Sections **//
        while select interfaceSection order by Sequence where interfaceSection.InterfaceDefinition == _message.InterfaceDefinition && interfaceSection.SectionStagingTable != ''
        {
            if (interfaceSection)
            {
                if (!map.exists(interfaceSection.SectionStagingTable))
                {
                    map.insert(interfaceSection.SectionStagingTable, interfaceSection.InterfaceSectionId);
                }
                else
                {
                    map.insert(interfaceSection.SectionStagingTable, map.lookup(interfaceSection.SectionStagingTable));
                }
            }
        }
        if (!map.empty())
        {
            mapEnum = map.getEnumerator();
            while (mapEnum.moveNext())
            {
                idx++;
                stagingTableName = mapEnum.currentKey();
                sectionName = mapEnum.currentValue();
                dictTable = new DictTable(tablename2id(stagingTableName));
 
                // Add a data source to the form
                formBuildDataSource = form.addDataSource(dictTable.name());
                formBuildDataSource.table(dictTable.id());
                // TabPage Control
                formBuildTabPageControl = formBuildTabControl.addControl(FormControlType::TabPage, sectionName+enum2Str(FormControlType::TabPage));
                formBuildTabPageControl.caption(sectionName);
                formBuildTabPageControl.heightMode(FormHeight::SizeToContent);
                if (idx == 1)
                {
                    formBuildTabPageControl.fastTabExpanded(FastTabExpanded::Always);
                }
                else
                {
                    formBuildTabPageControl.fastTabExpanded(FastTabExpanded::Auto);
                    formBuildTabPageControl.verticalScrollBarVisible(true);
                }
                // Grid Control
                formBuildGridControl = formBuildTabPageControl.addControl(FormControlType::Grid,sectionName+enum2Str(FormControlType::Grid));
                if (idx == 1)
                {
                    formBuildGridControl.visibleRowsMode(AutoMode::Fixed);
                    formBuildGridControl.visibleRowsValue(1);
                    formBuildGridControl.visibleRows(1);
                    formBuildGridControl.heightMode(FormHeight::SizeToContent);
                }
                else
                {
                    formBuildGridControl.visibleRowsMode(AutoMode::fixed);
                    formBuildGridControl.visibleRows(10);
                    formBuildGridControl.visibleRowsValue(10);
                    formBuildGridControl.heightMode(FormHeight::SizeToAvailable);
                }
                // Add data fields to Grid
                CG_EDI_EDIMessageStatus::addFields2Grid(dictTable, formBuildGridControl,formBuildDataSource);
            }
        }
        args = new Args();
        args.object(form);
 
        // Create the run-time form.
        formRun = classfactory.formRunClass(args);
        formRun.init();
 
        // filter the selected message's ExecutionId
        for (int i = 1; i <= idx; i++)
        {
            formDataSource = formRun.dataSource(i);
            qbds = formDataSource.query().dataSourceNo(1);
            qbds.firstFast(false);
            qbds.firstOnly(false);
            qbr = qbds.addRange(fieldName2Id(qbds.table(),"ExecutionId"));
            qbr.value(_message.ExecutionId);
            qbr.status(RangeStatus::Hidden);
            formDataSource.executeQuery();
            int counter = formDataSource.numberOfRowsLoaded();   // => this counter shows 3 records for the second datasource!
        }
        formRun.run();
        formRun.detach();
    }
 
 
and this is how my form shows up:
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    First of all, make sure that each grid is linked to the right data source. I don't think it's the case, because I don't see any such code. You should do it via formGridControl.dataSource(formBuildDataSource.name()).
     
    Fix it and check the result.
     
    If you still have a problem, realize that what data gets fetched is defined by a query, therefore if the query returns something else than you expect, the query itself isn't what you expect. Therefore you should look at the query difinition. For example, there may be an automatically created dynamic link. As you've already found, just looking at the returned data doesn't tell you much.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
    Hi @ulli_d,
     
    Try to use TraceParser to get Sql Statement.
     
    Best regards,
    Mohamed Amine MAHMOUDI

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans