Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 5
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:
  • Martin Dráb Profile Picture
    Martin Dráb 230,320 Most Valuable Professional on at
    Form created with X++ with multiple datasources shows only 1 record
    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.

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,308 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,320 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans