0

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

Astoner
  • 55
  • 1
  • 9
  • What help do you need? – Jan B. Kjeldsen Oct 13 '15 at 06:53
  • "How do I associate vendor product receipt lines (VendPackingSlipTrans) with purchase lines (PurchLine)?"... Is that the question? – ian_scho Oct 13 '15 at 07:09
  • 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 Oct 13 '15 at 07:18
  • @ian_scho Yes and get value of `LineAmount` because i want this value in staging table – Astoner Oct 13 '15 at 07:50
  • @FH-Inway can you help to correct this select statement – Astoner Oct 13 '15 at 07:53
  • @Astoner: I'm still trying to understand what you are trying to do. It seems you to want to import `VendPackingSlipTrans` records (which is not a good idea in itself), but your source (whatever that is) cannot provide a line amount (but then why do the import in the first place if such a central information is missing?). So instead you want to use the line amount of the purchase order line. You would need the `InventTransId` of the purchase order line for that, but your source probably does not have this information. If these guesses are correct, you may want to reconsider your requirements. – FH-Inway Oct 13 '15 at 13:53
  • @FH-Inway 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 – Astoner Oct 13 '15 at 14:09
  • @Astoner: Please move the information you have provided in the comments into your question. – FH-Inway Oct 13 '15 at 15:49

1 Answers1

2

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;
}
FH-Inway
  • 4,432
  • 1
  • 20
  • 37
  • Thank you you are the best , your explication help me to learn new things – Astoner Oct 13 '15 at 17:12
  • I get the following error when i try to test my export by create a new Target entities in Data import export framword>Target entities :`Error executing code: DMFVendPackingSlipTransClass object does not have method getFieldsSequence` I want to answer new question,but i have reached my question limit sorry for that – Astoner Oct 14 '15 at 10:22
  • @Astoner: take a look how other DIXF entity classes implement this method, e.g. `DMFPurchLineEntityClass`. This should give you an idea how you can implement the method in your own `DMFVendPackingSlipTransClass`. – FH-Inway Oct 14 '15 at 13:26
  • Thank you , i fixed my error i forget extends DMFEntityBase for my class – Astoner Oct 14 '15 at 15:40