0
votes

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

1
What help do you need? - Jan B. Kjeldsen
"How do I associate vendor product receipt lines (VendPackingSlipTrans) with purchase lines (PurchLine)?"... Is that the question? - ian_scho
The select statement and the following logic to set field LineAmount does not make any sense. As it is currently written, LineAmount will always be zero because the select statement will retrieve a PurchLine record with an empty PurchId and a LineNumber of zero (because the vendPackingSlipTrans variable is never instantiated) and unless you have corrupt data, such a PurchLine record should not exist. Also it doesn't make sense to call entity.insert() in this method. Generate methods are used to set one field of the entity record, not to insert the entity record. - FH-Inway
@ian_scho Yes and get value of LineAmount because i want this value in staging table - Astoner
@FH-Inway can you help to correct this select statement - Astoner

1 Answers

2
votes

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;
}