linkType is not JoinMode type, it is FormLinkType enum, correct way would be:
dBDS.linkType(FormLinkType::InnerJoin);
"Mathias" wrote:
> Hello,
>
> add a new formdatasource on runtime is not easy and works not very well.
>
> Here is an example to add a new formdatasource. If you use it on form
> Inventtable you will most likly get an error because of some code that is in
> the init method of the form (for testing you have to remove this codeline).
> There is this strange behavior of the formcontrols that are modified by x++
> are not formcontrols anymore, but formdatasources? Anyway here is the example
> (does not work very well but you can see - good luck :)
>
> FormRun frmInventTable, newFrmInventTable;
> FormDataSource dsInventTable;
> Query qMyQuery;
> FormBuildDataSource dBDS;
> FormStringControl fsc;
> args args = new Args();
> ;
>
>
>
> frmInventTable = ClassFactory::formRunClassOnClient(new
> Args(formStr(InventTable)));
> frmInventTable.init();
>
> dsInventTable= frmInventTable.dataSource(1);
>
> //add new FormDataSource
> dBDS = frmInventTable.form().addDataSource("InventModule");
> //set Table
> dBDS.table(tablenum(InventModelGroup));
> //set Join
> dBDS.joinSource(
dsINventTable.name());
> dBDS.linkType(Joinmode::InnerJoin);
>
> // add control to design
> fsc =
> frmInventTable.form().design().control("Grid").addDataField(dBDS.id(),
> fieldnum(InventModelGroup, Name));
> //create new formrun based on current form
> args.object(frmInventTable.form());
> //close current formrun
> frmInventTable.close();
>
> newFrmInventTable = new Formrun(args);
> newFrmInventTable.init();
> newFrmInventTable.run();
> newFrmInventTable.wait();
>
>
> For further information take a look at class systablebrowser.
>
> Kind regards
> --
> Mathias Füßler
> my blog:
http://starside.eu
>
>
>
> "Strider" wrote:
>
>> Thanks.
>>
>> I used a similar approach, modifying the existing datasource query and it
>> worked (at least when adding ranges to the existing datasources).
>> There is still a problem though. If I add a new QueryBuildDatasource to the
>> query (e.g. InventModelGroup),
>> no corresponding FormBuildDataSource is added to the form. When the form
>> opens, the additional table is not joined in the statement issued to the
>> database server.
>>
>> I tried creating the FormBuildDataSource manually but it still doesn't work!
>>
>> "Mathias" wrote:
>>
>>> Hello Strider,
>>>
>>> here is an example that uses a new query based on the inventtable query. It
>>> adds one range only.
>>>
>>> FormRun frmInventTable;
>>> FormDataSource dsInventTable;
>>> Query qMyQuery;
>>> ;
>>>
>>>
>>>
>>> frmInventTable = ClassFactory::formRunClassOnClient(new
>>> Args(formStr(InventTable)));
>>> frmInventTable.init();
>>>
>>> dsInventTable= frmInventTable.dataSource(1);
>>> //get invent table query
>>> qMyQuery = new Query(dsInventTable.query());
>>> // Initialize query object starting from InventTable here
>>>
>>> qMyQuery.dataSourceTable(tablenum(InventTable)).addRange(fieldnuM(InventTable, ItemID)).value("test");
>>> dsInventTable.query(qMyQuery);
>>>
>>> frmInventTable.run();
>>> frmInventTable.wait();
>>>
>>> I hope this will help.
>>>
>>> Kind regards
>>> --
>>> Mathias Füßler
>>> my blog:
http://starside.eu
>>>
>>>
>>>
>>> "Strider" wrote:
>>>
>>>> Thanks for replying Mathias.
>>>>
>>>> I've tried replacing the FormDataSource.query with my query but I end up
>>>> getting a form with no data. The problem is that the InventTable form has
>>>> many linked data sources under the main datasource, which are removed when I
>>>> set the query property.
>>>>
>>>> "Mathias" wrote:
>>>>
>>>>> Hello Strider,
>>>>>
>>>>> try using
>>>>> dsInventTable.query(qMyQuery);
>>>>> instead of
>>>>> dsInventTable.queryRun(new QueryRun(qMyQuery);
>>>>>
>>>>> Kind regards
>>>>> --
>>>>> Mathias Füßler
>>>>> my blog:
http://starside.eu
>>>>>
>>>>>
>>>>>
>>>>> "Strider" wrote:
>>>>>
>>>>>> Hello.
>>>>>>
>>>>>> I need to show the InventTable (Items) form from code, and filter it's
>>>>>> contents using a Query object I have also constructed from code. I have tried
>>>>>> the following, but it does not seem to work:
>>>>>>
>>>>>> FormRun frmInventTable;
>>>>>> FormDataSource dsInventTable;
>>>>>> Query qMyQuery;
>>>>>> ;
>>>>>>
>>>>>> qMyQuery = new Query();
>>>>>> // Initialize query object starting from InventTable here
>>>>>> //
>>>>>>
>>>>>> frmInventTable = ClassFactory::formRunClassOnClient(new
>>>>>> Args(formStr(InventTable)));
>>>>>> frmInventTable.init();
>>>>>> dsInventTable= frmInventTable.dataSource(1);
>>>>>> dsInventTable.queryRun(new QueryRun(qMyQuery);
>>>>>>
>>>>>> frmItems.run();
>>>>>> frmItems.wait();
>>>>>>
>>>>>>
>>>>>> The items form is displayed but my query is ignored and no filter is applied!
>>>>>> Please note that the Query must be constructed from code outside the
>>>>>> InventTable form.
>>>>>>
>>>>>> Has anyone done this allready?
>>>>>> Any help would be greatly appreciated.
>>>>>> Thanks!