Wednesday, July 26, 2023

Cannot create a record in Product Modeling Policy (EcoResProductMasterModelingPolicy). Reference: 0, No. The record already exists. In AX 2012 R3

 DIXF Product entity returns the following error for every product. 

Explanation

DIXF Product entity loaded data into target data sources based on descending sequence number (DMFTargetEntityHierarchy.SequenceNo), and EcoResProductMasterModelingPolicy is the first table to get loaded (Seq. No. 22 out of 22 target data sources).


However, records cannot be inserted into EcoResProductMasterModelingPolicy if it does not have a valid ProductMaster.RecId available for reference.

This makes sense since EcoResProductMasterModelingPolicy is getting populated before EcoResProduct (which also populates EcoResProductMaster to provide a RecId). 

Solution

To fix this, I changed the seq. no. of EcoResProduct to 23, making it the largest value so it will get selected and populated first in the while loop.




static void EcoResProductSequenceUpdate(Args _args)

{

    DMFTargetEntityHierarchy DMFTargetEntityHierarchy;

    select forupdate DMFTargetEntityHierarchy

        where DMFTargetEntityHierarchy.recid == 5637145349;

    if (DMFTargetEntityHierarchy)

    {

        ttsbegin;

        DMFTargetEntityHierarchy.SequenceNo = 23;

        DMFTargetEntityHierarchy.doupdate();

        info('done');

        ttsCommit;

    }

}

No comments:

Post a Comment