Item - Import::OnBeforeModifyRecord() IF Item.GET(No) AND Item.FINDFIRST THEN BEGIN Item.SETRANGE("No.",No); EVALUATE(Item."No.",No); EVALUATE(Item.Description, Description); EVALUATE(Item."Base Unit of Measure", BaseUnitOfMeasure); EVALUATE(Item."Item Category Code", ItemCategoryCode); EVALUATE(Item."Product Group Code", ProductGroupCode); EVALUATE(Item."Unit Cost", UnitCost); EVALUATE(Item."Last Direct Cost", LastDirectCost); EVALUATE(Item."Gen. Prod. Posting Group",GenProdPostingGroup); EVALUATE(Item."VAT Prod. Posting Group",VATProdPostingGroup); EVALUATE(Item."Item Tracking Code", ItemTrackingCode); EVALUATE(Item."Sales Unit of Measure", BaseUnitOfMeasure); Item.VALIDATE(Item."VAT Bus. Posting Gr. (Price)", 'NAC'); Item.VALIDATE(Item."Inventory Posting Group", 'PROD'); Item.VALIDATE(Item."Item Disc. Group",'ALL'); Item.MODIFY(TRUE); MESSAGE('Produto %1 atualizado com sucesso', No); END ELSE BEGIN nbOfError += 1; MESSAGE('Ocorreu um erro a atualizar o produto %1', No); END; Item - Import::OnBeforeInsertRecord() MESSAGE('no %1',No); IF NOT Item.GET(No) THEN BEGIN EVALUATE(Item."No.",No); EVALUATE(Item.Description, Description); EVALUATE(Item."Base Unit of Measure", BaseUnitOfMeasure); EVALUATE(Item."Item Category Code", ItemCategoryCode); EVALUATE(Item."Product Group Code", ProductGroupCode); EVALUATE(Item."Unit Cost", UnitCost); EVALUATE(Item."Last Direct Cost", LastDirectCost); EVALUATE(Item."Gen. Prod. Posting Group",GenProdPostingGroup); EVALUATE(Item."VAT Prod. Posting Group",VATProdPostingGroup); EVALUATE(Item."Item Tracking Code", ItemTrackingCode); EVALUATE(Item."Sales Unit of Measure", BaseUnitOfMeasure); Item.VALIDATE(Item."VAT Bus. Posting Gr. (Price)", 'NAC'); Item.VALIDATE(Item."Inventory Posting Group", 'PROD'); Item.VALIDATE(Item."Item Disc. Group",'ALL'); Item.INSERT(TRUE); nbOfSuccess += 1; MESSAGE('Produto %1 inserido com sucesso', No); END Item Unit of Measure - Import::OnBeforeInsertRecord() MESSAGE('item unit of measure %1',ItemUnitOfMeasure); IF NOT "Item Unit of Measure".GET(No,BaseUnitOfMeasure) THEN BEGIN EVALUATE("Item Unit of Measure"."Item No.",No); EVALUATE("Item Unit of Measure".Code, BaseUnitOfMeasure); "Item Unit of Measure".INSERT(TRUE); MESSAGE('Produto %1 inserido em "Item Unit of Measure"', No); END ELSE BEGIN nbOfError += 1; MESSAGE('Ocorreu um erro a acrecentar o produto %1 em "Item Unit of Measure"', No); END; Item Unit of Measure - Import::OnAfterInsertRecord() Item Unit of Measure - Import::OnBeforeModifyRecord() MESSAGE('item unit of measure %1',ItemUnitOfMeasure); IF "Item Unit of Measure".GET(No,BaseUnitOfMeasure) AND "Item Unit of Measure".FINDFIRST THEN BEGIN "Item Unit of Measure".SETRANGE("Item No.",No); "Item Unit of Measure".SETRANGE(Code,BaseUnitOfMeasure); EVALUATE("Item Unit of Measure"."Item No.",No); EVALUATE("Item Unit of Measure".Code, BaseUnitOfMeasure); "Item Unit of Measure".MODIFY(TRUE); MESSAGE('Produto %1 atualizado em "Item Unit of Measure"', No); END ELSE BEGIN nbOfError += 1; MESSAGE('Ocorreu um erro a acrecentar o produto %1 em "Item Unit of Measure"', No); END; CodBarras - Import::OnBeforeModifyRecord() MESSAGE('barcode %1',Barcode); IF CodBarras.GET(Barcode) AND CodBarras.FINDFIRST THEN BEGIN CodBarras.SETRANGE("Barcode No.",Barcode); EVALUATE(CodBarras."Item No.",No); EVALUATE(CodBarras."Barcode No.", Barcode); EVALUATE(CodBarras.Description, Description); EVALUATE(CodBarras."Unit of Measure Code",BaseUnitOfMeasure); EVALUATE(CodBarras."Last Date Modified",FORMAT(TODAY)); CodBarras.MODIFY(TRUE); MESSAGE('Produto %1 atualizado em "CodBarras"', No); END ELSE BEGIN nbOfError += 1; MESSAGE('Ocorreu um erro a modificar o produto %1 em "CodBarras"', No); END; CodBarras - Import::OnBeforeInsertRecord() MESSAGE('barcode %1',Barcode); IF NOT CodBarras.GET(Barcode) THEN BEGIN EVALUATE(CodBarras."Item No.",No); EVALUATE(CodBarras."Barcode No.", Barcode); EVALUATE(CodBarras.Description, Description); EVALUATE(CodBarras."Unit of Measure Code",BaseUnitOfMeasure); EVALUATE(CodBarras."Last Date Modified",FORMAT(TODAY)); CodBarras.INSERT(TRUE); MESSAGE('Produto %1 inserido em "CodBarras"', No); END ELSE
Answers
-When exporting? Is the file good? Does it contain all columns?
-When importing, check with the debugger if it goes by the code
-
-I would use Import::OnBeforeInsertRecord() and the last dataitem ( and try with temporary=yes in properties) codbarras. do all there, check if exists the item, if not, insert, check if exists barcode, if not insert..
Another approach easy, if this is something you will run once, it´s to sepparate item dataport, barcode dataport...
This may ease you.
IF <AnyRec>.GET(<Value>) AND <AnyRec>.FINDFIRST THEN BEGIN
should be preceded by <AnyRec>.SETRANGE(<Primary Key>, <Value>);
because your code find first key value ever.