Search code examples
axaptadynamics-ax-2012x++dynamics-ax-2012-r3

DMF/DIXF AX 2012 R3 Custom generate method


I'm working around File Exchange (Export) using Data Import Export Framework (DIXF) , i want to add generate method to Find LineAmount Purchline associated with the receiving line VendPackingSlipTrans from PurchLine table.I create the following script but i need a help :

[DMFTargetTransformationAttribute(true),DMFTargetTransformationDescAttribute("Function that generate LineAmount"),
 DMFTargetTransformationSequenceAttribute(11),
 DMFTargetTransFieldListAttribute([fieldStr(DMFVendPackingSlipTransEntity,LineAmount)])
]
public container GenerateLineAmount(boolean _stagingToTarget = true)
{

    container                  res;
    PurchLine                  purchLine;
    VendPackingSlipTrans       vendPackingSlipTrans;

    if (_stagingToTarget)
    {
        select firstOnly purchLine
            where purchLine.LineAmount                  == entity.LineAmount &&
                  vendPackingSlipTrans.OrigPurchid      == purchLine.PurchId &&
                  vendPackingSlipTrans.PurchaseLineLineNumber == purchLine.LineNumber;

        if ( ! purchLine )
        {
            entity.LineAmount = purchLine.LineAmount ;
            entity.insert();
        }
    }
    res = [entity.LineAmount];
    return res;
}

I have to export data from ax to file using DMF,so for that i have some field existing in VendPackingSlipTrans so added this fields in staging table but others field exist in other table like LineAmount.I don't know how to add this others fields in staging table. for that in myEnityclass i create generat method to associate field in source table. to staging table


Solution

  • So it seems you want to export VendPackingSlipTrans records with additional information from PurchLine records using a custom entity of the data import/export-Framework (DIXF). If that is correct, there are several problems in your implementation:

    1. logic in if (_stagingToTarget) branch: since the framework can be used for both import and export, _stagingToTarget is used to distinguish between the two. If _stagingToTarget is true, data is imported from the staging table to the Dynamics AX target table. So you need to put the logic in the else branch.
    2. selection of PurchLine record: the current implementation will never select a PurchLine record because values of an uninstantiated VendPackingSlipTrans table variable are used as criteria in the select statement. Also the chosen criteria are wrong, take a look at method purchLine of table VendPackingSlipTrans to see how to get the PurchLine record for a VendPackingSlipTrans record and use the target variable to instantiate the VendPackingSlipTrans table variable.
    3. check if (! purchLine): This check means that if NO PurchLine record could be found with the previous select statement, the LineAmount of this empty record will be used for the staging record. This is wrong, instead you want to use the LineAmount of a record that has been found.
    4. entity.insert(): as I mentioned in the comments, the entity record should not be inserted in a generate method; the framework will take care of the insert

    A possible fix of these problems could look like this:

    [
        DMFTargetTransformationAttribute(true),
        DMFTargetTransformationDescAttribute('function that determines LineAmount for export'),
        DMFTargetTransformationSequenceAttribute(11),
        DMFTargetTransFieldListAttribute([fieldStr(DMFVendPackingSlipTransEntity, LineAmount)])
    ]
    public container GenerateLineAmount(boolean _stagingToTarget = true)
    {
        container                  res;
        PurchLine                  purchLine;
        VendPackingSlipTrans       vendPackingSlipTrans;
    
        if (_stagingToTarget)
        {
            // this will be executed during import
            res = [0.0];
        }
        else
        {
            // this will be executed during export
            // the target variable contains the VendPackingSlipTrans that is exported
            vendPackingSlipTrans = target;
            purchLine = vendPackingSlipTrans.purchLine();
            if (purchLine)
            {
                res = [purchLine.LineAmount];
            }
        }
        return res;
    }