Intercompany order connection

Legal Entity1
Legal Entity2
Legal Entity3

LE1 SO -> LE1 PO -> LE2 SO

LE1 SO -> LE1 PO Link:
salesLine.InventRefType == InventRefType::Purch
salesLine.InventRefTransId == purchLine.InventTransId
salesLine.InventRefId == purchLine.PurchId
LE1 PO -> LE1 SO Link:
purchLine.InventRefTransId == salesLine.InventTransId
purchLine.InventRefId == salesLine.SalesId

salesLine.InterCompanyOrigin == InterCompanyOrigin::Source

LE1 PO -> LE2 SO Link
purchLine.InterCompanyOrigin == InterCompanyOrigin::Derived
purchLine.InterCompanyInventTransId == salesLine.InventTransId
LE2 SO -> LE1 PO Link
salesLine.InterCompanyOrigin == InterCompanyOrigin::Derived
salesLine.InterCompanyInventTransId == PurchLine.InventTransId

LE2 SO -> LE1 SO
SalesTable.InterCompanyOrder == NoYes::Yes
SalesTable.InterCompanyCompanyId == LE2
SalesTable.InterCompanyOriginalSalesId == SalesTable.SalesId

LE2 SO -> LE1 PO
SalesTable.InterCompanyOrder == NoYes::Yes
SalesTable.InterCompanyPurchId == PurchTable.PurchId

Intercompany links in UI
Path: Sales Order details / General / Related information / Related orders
Form: SalesTableReferences
Table: InterCompanyPurchSalesReference

Using the child sales line (LE2 SO), find the parent sales line (LE1 SO)
        SalesLine getSourceSalesLine(SalesLine _salesLine)
            SalesLine sourceSalesLine;
            PurchLine sourcePurchLine;

            select firstonly crosscompany RecId from sourcePurchLine
                where sourcePurchLine.InterCompanyInventTransId == _salesLine.InventTransId
                join sourceSalesLine
                    where sourceSalesLine.DataAreaId == sourcePurchLine.DataAreaId
                       && sourceSalesLine.InventRefType == InventRefType::Purch
                       && sourceSalesLine.InventRefTransId == sourcePurchLine.InventTransId;

            return sourceSalesLine;
Find the root order line if the intercompany chain consists of more orders (LE1 SO -> LE1 PO -> LE2 SO -> LE2 PO -> LE3 SO):
        SalesLine salesLineUpdate = this; // this == SalesLine

        while (salesLineUpdate.InterCompanyInventTransId && salesLineUpdate.InterCompanyOrigin != InterCompanyOrigin::Source)
            salesLineUpdate = getSourceSalesLine(salesLineUpdate);



About is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags