I need to add view to standard form

Hello…

I created a view and added it to standard form

there is no relation in table InventTable with view , so i need to create it in the form data source InventTable

the relation will be MyView.product and inventTable.Product

[ExtensionOf(formDataSourceStr(PriceDiscTable, InventTable))]
final class zz_PriceDiscTable_Form_init_AddFields_Extension
{
    public void init()
    {
        next  init();

        QueryBuildDataSource    queryBuildDataSource;

        queryBuildDataSource = this.query().dataSourceTable(tableNum(InventTable));
        queryBuildDataSource.addDataSource(tableNum(zz_ProductCategory));
        queryBuildDataSource.relations(false);

        queryBuildDataSource.addLink(fieldnum(zz_ProductCategory, Product),fieldnum(InventTable, Product));
        queryBuildDataSource.joinMode(JoinMode::OuterJoin);

    }

}

also test next but give me : data source is not embedded within a (parent) data source.

[ExtensionOf(formDataSourceStr(PriceDiscTable, zz_ProductCategory))]
final class zz_PriceDiscTable_Form_init_AddFields_Extension
{
    public void init()
    {
        next  init();

        this.queryBuildDataSource().relations(false);
        
        this.queryBuildDataSource().addLink(fieldNum(InventTable, Product),
            fieldNum(zz_ProductCategory, Product));

    }

}

when build and test there is no duplication on form but no data displayed from the view in grid

Thanks all

Welcome to the group, Ahmed!

Your first code snippet ignores the form data source you added to the form and it just adds a query data source in code. I think it’s not what you want. By the way, you have a wrong order of fields in addLink() there (it’s correct in your second code snippet).

The second code snippet looks fine, although you can remove relations(false). It does nothing if there are no relations. I suspect the message is caused by the fact that you’ve set a wrong LinkType. Make sure it’s a join (your first snippet suggests an outer join), not a link such as Delayed. You may need to call it from init() of InventTable data source instead (I’m not sure how exactly it behaves, but try it and you’ll see).

Thanks Jake [emoticon:578cee8aac0e41e9bcef50a2f8d281d5]

My problem was in relation , but I have a q why first solution is wrong (Your first code snippet ignores the form data source you added to the form and it just adds a query data source in code.)

In this snippet I use also the same qbds that get from query

You added a form data source, which automatically added a QueryBuildDataSource as well. But then your code added another QueryBuildDataSource for zz_ProductCategory table, unrelated to the form data source.