Changing data source linktype from "Delayed" to "Inner"

Good afternoon,

I’m working on a microsoft form which has the PurchLine as the primary datasource and PurchTable as a child, set to the delayed linktype. I need to change this linktype as I need to add purchTable fields to the grid on the form, and with the delayed type it only loads one purchTable record at a time.

This linktype can’t be changed through a form extension. When I’ve debugged I can see that following the init, the purchTable form datasource essentially operated independently from the main form query, loading a single record at a time. Has anyone solved this problem before? I’ve tried all the usual ways, but adding the datasource doesn’t work as it already exists as a datasource on the form, and I can’t find a way to link the existing datasources together.

You’re wrong in thinking that you can’t add another data source for the same table.
Also, you should be able to change the link to a join by code when initializing the form. For example:

purchTable_ds.queryBuildDataSource().joinMode(JoinMode::InnerJoin);

Note that links are joins are quite different things, therefore you may need to do extra changes to the form to get everything working correctly.

Hi Martin,

This is where I’m having the issue. This is on the PurchLineOpenOrder form. When I debug, the PurchLine_DS does not have the PurchTable as a child datasource in its querybuilddatasource, and the PurchTable_DS runs quite separately with PurchTable as the parent datasource in its own seperate query.

I misspoke when I said I can’t add the datasource. What I meant is that the PurchTable is already initialized anywhere in the code that I can make meaningful changes, so I can’t make a change that adds it as a child to the PurchLine_DS. I think I’m going to need to add an additional instance of PurchTable to the form extension and use that for the additional fields.

I’ve been trying to avoid that though to avoid adding unnecessary overhead to the form.

Thanks for the response.

Yes, linked data sources are two linked queries, not a single query with joined data sources.
You say you “can’t make a change”, but why not? I think you should be able.
Not touching the standard data source and using a custom one may be safer, therefore I’m not going to push you to reuse the exising one, but it should be possible.

Hi Martin,

If you switch to inner join you receive an error saying the purchtable datasource is not a child datasource. It seems to expect the QBDS of PurchTable_DS to be a child of the QBDS for PurchLine_DS if it is linked via an inner join. This makes sense as that’s how any datasources on the form that were inner in the parameters are setup.

To my knowledge there isn’t a way to make the already established QBDS on PurchTable_DS a child of the purchLine QBDS once it’s already initialised and assigned to PurchTable_DS, and you can’t work it the other way either. You can’t add a PurchTable datasource as a child to the PurchLine_DS then assign this QBDS to PurchTable_DS as this doesn’t take assignment.

Ideally MS would just allow you to change the link type on the datasource through the form extension, but a man can only dream.

Please be more specific. Where and how did you change the link type? I agree that you can’t do it after data sources were intialized - that’s for sure. That can’t work. You’d need to it during intialization, not after.
It’s not that is “expects the QBDS of PurchTable_DS to be a child of the QBDS for PurchLine_DS if it is linked via an inner join”. It’s the other way around. If you join data sources, they form a single query. If you link them, you get two separate queries.
Anyway, if you’re struggling with it, simply leave the standard DS as it is and add one more for your purpose.

Hi Martyn,

So a full summary. I need to add PurchTable fields to the grid on the PurchLineOpenOrder form. When adding fields to the grid, the fields only appear on the first line on the grid, and the field values on this line change to reflect the currently selected record. This appears to be because the datasource is set to “Delayed” in the linktype on the parameters of the form datasource.

The code I’m using is in a chain of command call to the init method of the form, after the next call. I’ve tried the same code on the init of the PurchTable datasource after the next.

When using the line “PurchTable_ds.linkType(FormLinkType::InnerJoin);”, I receive the following error.

Query missing QueryBuildDataSource for FormDataSource PurchTable.

So from what you’ve said, I suspect that if the initial setting was any of the joins (outer, inner, etc), changing to another type of join using PurchTable_ds.linkType() would work fine, as the datasource would be created with a QBDS as a child of the PurchLine QBDS. Since the datasource was created as “delayed”, the QBDS for PurchTable is not created as a child of the PurchLine QBDS.

This appears to stop me switching to innerjoin as I can’t make the QBDS on PurchTable_DS into a child of PurchLine_DS QBDS, and I can’t create a new QBDS as a child of PurchLine_DS and assign it to PurchTable_DS.

Unless there’s something you can suggest?

Sure, you can’t assign another data source to PurchTable_DS. I don’t understand why you want to do such a thing.
Create a new joined data source and then use fields from this data source in the grid.

The point was to try and switch the existing PurchTable datasource to an innerjoin rather then a delayed link to avoid having 2 separate PurchTable datasources on the same form, as having 2 separate queries to the same data seemed inefficient.

Since switching this to an innerjoin requires PurchTable to be a child datasource of PurchLine, I was looking at either making the existing QBDS of PurchTable_DS a child of PurchLine_DS (not possible), or creating a new child QBDS of type PurchTable on the PurchLine and assigning this to PurchTable_DS (also not possible).

I’ve not just created a new PurchTable datasource in the form extension and am using this for the fields. The form will just have to query the PurchTable twice. At least the delayed link means that the default query to PurchTable will be very limited.

I gave it a try and it seems that code like this does the job:

[ExtensionOf(formDataSourceStr(PurchLineOpenOrder, PurchTable))]
internal final class MyPurchLineOpenOrder_PurchTable_Extension
{
    public void init()
    {
        this.linkType(FormLinkType::InnerJoin);
        next init();
    }
}

Hi Martyn,

Thank you! I honestly didn’t think of trying it before the next init call because in most cases you just have an empty constructed object, and the main init logic would wipe out anything you set.

I suppose datasources must load the parameters from the form design when it’s constructed?

This is now working without the need for an additional datasource on the form.