Dynamics AX queries with multiple top level datasource in forms

Hi,

My form has 2 data sources namely DirpartyTable,CustTable. the form displays customer data.

i have to perform a like search based on the following criteria

the form should filter all the customers which has the name like ‘XYZ’. i have written the query in the job and it works great.

static void like_search_Job(Args _args)

{

DirPartyTable dirPartyTable;

CustTable custTable;

QueryBuildDataSource qbds;

QueryBuildDataSource qbdsDirpartyTable;

QueryBuildDataSource qbdsCustTable;

QueryBuildRange qbr;

Query query = new Query();

QueryRun queryRun;

Counter c;

;

qbds = query.addDataSource(tableNum(DirPartyTable));

qbr = qbds.addRange(fieldNum(DirPartyTable,Name));

qbr.value(“Not*”);

qbdsCustTable = qbds.addDataSource(tableNum(custTable));

qbdsCustTable.relations(true);

qbdsCustTable.joinMode(JoinMode::InnerJoin);

queryRun = new QueryRun(query);

while(queryRun.next())

{

custTable = queryRun.get(tableNum(CustTable));

info(custTable.AccountNum);

c++;

}

info(int2str(c));

but when i try to implement the same on in the form it doesnt work for me. I believe you an join multiple tables simultaneously because it gives me following error 'Queries with multiple top level data sources cannot be applied to Forms.

here is the snippet of my executequery() method.

public void executeQuery()

{

q = new Query();

qbds = this.query().addDataSource(tableNum(DirPartyTable));

qbr = qbds.addRange(fieldNum(DirPartyTable,Name));

qbr.value(queryValue(orgName.valueStr()));

qbdsCustTable = qbds.addDataSource(tableNum(custTable));

qbdsCustTable.relations(true);

qbdsCustTable.joinMode(JoinMode::InnerJoin);

super();

}

Please advice how i can fix this and show customer records.

hi All,

i would apreciate any help on this.

You code tries to add two new data sources every time the query executes, which is clearly wrong.

Why did you write any code for that at all? Simply add data sources at design time and you’ll get rid of your buggy code.

1 Like

Yes… I agree with Martin.

Add your datasources at the Form level and simply write the code for filtering in executeQuery method.