Skip to content

[BUG] Bi-directional Product Relationship record creation is inconsistent and breaks environment #750

Description

@jecdx

Describe the bug
We execute an INSERT script to insert multiple Bi-Directional, Substitute records into the productsubstitute table.
For Bi-Directional records, the productsubstitute table is meant to have an A -> B record and a twin/reverse B -> A record. All of the "A -> B" records are created as expected, but an inconsistent and unpredictable amount of the "B -> A" records are created.

The records that are missing the twin are in a broken state.

  • Manually attempting to create the twin results in an error.
  • Attempting to delete the 'orphaned' record errors out, whether deleting from SQL 4 CDS or from the Dynamics web UI of a model-driven app.
    • Exception Message: The other row for the product relationship is not available.

    • Full error details: Delete-ErrorDetails.txt

The only way we were able to fix these records was to reach out to Microsoft support who were able to run a script of their own (not runnable in SQL 4 CDS) to delete the problem records.
Our workaround in this case was to manually create the needed Product Relationship records using our existing model-driven app.

To Reproduce
Query to reproduce the behavior:

INSERT INTO productsubstitute (productid, substitutedproductid, salesrelationshiptype, direction)
SELECT
    ptid.productid,
    p.productid,
    3, -- Substitute
    1  -- Bi-Directional
FROM product p
INNER JOIN cdm_company c            ON p.msdyn_companyid     = c.cdm_companyid
INNER JOIN msdyn_productcategory pc ON p.pre_productcategory = pc.msdyn_productcategoryid
INNER JOIN product ptid             ON ptid.productnumber    = 'SomeProductNumber'
WHERE
    c.cdm_companycode = '1234' -- Example company code
    AND pc.msdyn_code = '4444' -- Example code
    AND p.productnumber <> 'SomeProductNumber' -- Avoid associating with itself.

The intention of the script is to set all of the products with the expected company and product category as substitutes for the product with SomeProductNumber.

p.pre_productcategory is a lookup column to the Product Category table.

Expected behavior
All of the records and their twins are created.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • SQL 4 CDS edition: XrmToolbox
  • Results of SELECT @@VERSION:
  • First observed with SQL 4 CDS 10.1.0.0 in XrmToolbox version 1.2025.7.71 (when these versions were latest) but also reproduced with later versions

Additional context
We opened a ticket with Microsoft. They were able to delete the problem records from our environment, but declined to look into the root cause since XrmToolbox and SQL 4 CDS are third-party tools.

Sponsorship
If you find this tool useful, please consider sponsoring its development.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions