Hi all,
I have a form with multiple datasources. One of the datasources is NOT joined to any of the other datasources. This datasource is called CarTable_DS. The records for this datasource are loaded through code in the executeQuery method of the datasource.
Basically, I have a centralized method which constructs an X++ query object with all the ranges and returns the query to the caller. Apart from being used in the form, this method is used in a lot of other places and that is why I decided to centralize it. The method is called constructShowAllCarTypesQuery().
public Query constructShowAllCarTypesQuery()
{
Query qFirstTypeFrom;
Query qSecondTypeFrom;
Query qThirdTypeFrom;
QueryBuildDataSource qbdsFirstTypeFrom;
QueryBuildDataSource qbdsSecondTypeFrom;
QueryBuildDataSource qbdsThirdTypeFrom;
Query qUnion;
QueryBuildDataSource qbdsFirstTypeTo;
QueryBuildDataSource qbdsSecondTypeTo;
QueryBuildDataSource qbdsThirdTypeTo;
;
// Get all the datasources
qFirstTypeFrom = this.constructFirstTypeQuery();
qbdsFirstTypeFrom = qFirstTypeFrom.dataSourceTable(tableNum(CarsTable));
qSecondTypeFrom = this.constructSecondTypeQuery();
qbdsSecondTypeFrom = qSecondTypeFrom.dataSourceTable(tableNum(CarsTable));
qThirdTypeFrom = this.constructThirdTypeQuery();
qbdsThirdTypeFrom = qThirdTypeFrom.dataSourceTable(tableNum(CarsTable));
// Construct the query
qUnion = new Query();
qUnion.queryType(QueryType::Union);
qbdsFirstTypeTo = qUnion.addDataSource(tableNum(CarsTable), identifierStr("CarsTable_FirstType"));
DFMUtils::copyRanges(qbdsFirstTypeTo, qbdsFirstTypeFrom);
qbdsFirstTypeTo.fields().dynamic(false);
qbdsFirstTypeTo.fields().clearFieldList();
qbdsFirstTypeTo.fields().addField(fieldNum(CarsTable, CarId));
qbdsSecondTypeTo = qUnion.addDataSource(tableNum(CarsTable), identifierStr("CarsTable_SecondType"), UnionType::Union);
DFMUtils::copyRanges(qbdsSecondTypeTo, qbdsSecondTypeFrom);
qbdsSecondTypeTo.fields().dynamic(false);
qbdsSecondTypeTo.fields().clearFieldList();
qbdsSecondTypeTo.fields().addField(fieldNum(CarsTable, CarId));
qbdsThirdTypeTo = qUnion.addDataSource(tableNum(CarsTable), identifierStr("CarsTable_ThirdType"), UnionType::Union);
DFMUtils::copyRanges(qbdsThirdTypeTo, qbdsThirdTypeFrom);
qbdsThirdTypeTo.fields().dynamic(false);
qbdsThirdTypeTo.fields().clearFieldList();
qbdsThirdTypeTo.fields().addField(fieldNum(CarsTable, CarId));
return qUnion;
}
Now, in the executeQuery method on the form, I am doing this:
public void executeQuery()
{
Query q;
;
q = CarsTable.constructShowAllCarTypesQuery();
CarsTable_DS.query(q);
super();
}
However, when I now open the form, I am getting this error:
The join mode in union query is invalid. For a join query, the join mode of the second level data source must be either exists or notexists.
How can I solve this problem please? I tried to put the join mode in the constructAllCarTypes method to exists join for the second and third datasources to no avail. Furthermore, I wasn't able to find anything for this error on the internet.
P.S. Important Info. When running the query through a job, it works fine and returns the expected results. It is ONLY giving problems when trying to use it in a form in the way that I described above.
Thank you in advance!