relationship between two table in x++

i want to relate two tables in ax:

  • ConditionValidation
  • TMpFrmVirtual

with this code, after debugging i can’t see the relation between them:


Query query = new Query();
QueryBuildDataSource qdbs;

qdbs = query.addDataSource(tableNum(ConditionValidation));

qdbs = qdbs.addDataSource(tableNum(TmpFrmVirtual));

qdbs.joinMode(JoinMode::ExistsJoin);

qdbs.relations(true);

qdbs.addLink(fieldNum(ConditionValidation, RecId), fieldNum(TmpFrmVirtual, RefRecId));
QueryRun qr = new QueryRun(query);



what’s wrong with this code?

What do you mean by “seeing the relation”?

The problem with your code is that you’re querying a temporary table (TmpFrmVirtual) without providing any temporary buffer with data (unless you do it in code that your didn’t show), therefore TmpFrmVirtual will always be empty and your query will never return anything.

my tmpFrmVIrtual is full.

Sure, you can have values in a temporary buffer, but it’s irrelevant if you don’t pass it to the query.

I suspect you don’t understand what temporary tables are. Let me give you an example.

// Put a record to TmpFrmVirtual
TmpFrmVirtual tmp1;
tmp1.Id = 'Test';
tmp1.insert();

// Getting the record we've just inserted
TmpFrmVirtual tmp2;
select tmp2
    where tmp2.Id == 'Test';
    

We insert a record and try to read it, but we won’t find it. The reason is that there are two completely independent temporary buffers. We inserted the record to tmp1, while tmp2 is empty. Querying tmp2 can’t give you records that you put to tmp1.

Imagine that we’re working with Excel files. You write a value to A.xlsx and then you open B.xlsx and expect to find the same data there. It’s clearly not how it works.

And this is what happens with your query. You may have data in a buffer, but if you don’t say the query to run against it, it’ll query a new, empty buffer (like B.xlsx).

Do you know see why your code can’t work?

If so, it’s time to fix it. Call qr.setRecord() and use the buffer to which you’ve inserted the data as the parameter.