Filter records in DirPartyTableListPage form

87 Views Asked by At

I need to apply ExistsJoin with RestrictionTable to records in DirPartyTable that have InstanceRelation value = 123 and not filter the others in init method in form.

I tried this, but only records with InstanceRelationType == 123 are now in form but i need to keep other as well.

QueryBuildDataSource            qbdsRestriction;
QueryBuildRange                 qbr;


qbdsRestriction = dirpartyTable_ds.queryBuildDataSource().addDataSource(tableNum(RestrictionTable));            
qbr = qbdsRestriction.addRange(fieldNum(RestrictionTable, Party));
qbr.value(strFmt("((%1.Party == %2.RecId) && (%2.InstanceRelationType == 123))", qbdsRestriction.name(), dirpartyTable_ds.queryBuildDataSource().name()));
qbdsRestriction.joinMode(JoinMode::ExistsJoin);
2

There are 2 best solutions below

1
julia On BEST ANSWER

My problem was solved by making a union query for form datasource containing one view that was filtered with exist join and has range of InstanceRelation field = 123 and another view with unlimited value in InstanceRelation field --- the same way it was described here Get customer or prospects in Dynamics AX 2012

0
Alex Kwitny On

You're using expressions in query ranges, which need to be on a string field, I believe. I'm guessing RestrictionTable.Party is an int64. Choose some other, arbitrary string field and see if that fixes it, but you probably should not be using expressions in query ranges, and use the query object traditionally.

When I say that, I mean something similar to this:

QueryBuildDataSource            qbdsRestriction;
QueryBuildRange                 qbr;
    
qbr = dirpartyTable_ds.queryBuildDataSource().addRange(fieldNum(DirPartyTable, InstanceRelationType));
qbr.value(queryValue("123"));

qbdsRestriction = dirpartyTable_ds.queryBuildDataSource().addDataSource(tableNum(RestrictionTable));
// qbdsRestriction.clearLinks(); // This may be needed

// Method 1 OR
qbdsRestriction.addLink(fieldNum(DirpartyTable, RecId), fieldNum(RestrictionTable, Party));

// Method 2
// qbdsRestriction.relations(true); // Only if you have a table relation

qbdsRestriction.joinMode(JoinMode::ExistsJoin);

You would use qbdsRestriction.relations(true); if you have a table relation setup. If you have a table relation and do not want to use them, you would need false. If you do not have a table relation at all, then it's not needed and you would use // Method 1.

I don't have your exact data so I typed this from memory without intellisense, so you may need to tweak it and experiment.