change joinsource at runtime

I have a problem with the datasource.
I have a form with 2 datasources with these relations:
d1 (CustInvoiceJour) → d2 (CustInvoiceTrans)

Now I add a datasource d3 with temporary data and I would like the form would open in two different case (if I open the same form from different ways).

  1. d1 (CustInvoiceJour) → d2 (CustInvoiceTrans): the datasource d3 is empty and a I don’t use it.
  2. d3 (master) → d1 (CustInvoiceJour) → d2 (CustInvoiceTrans)

It’s possible setup at runtime the joinsource between d3 and d1 for the second case?
I tryed to create a joinsource by code but it don’t work with AX 4.0.

Thanks for your help!