xmlport can't insert barcode in table

catiamatos1991catiamatos1991 Member Posts: 158
Hi everyone,

I need to export table data from item/barcodes and item unit of measure table from one store to another. My idea is to always have the same info in this table in both of stores.

In order to do this I've created a xmlport to export data to a text file from item table. If table don't have the record it will be created, else if it exists I need to update.

Then I've created a xmlport to import data from text file to all this tables and I have the design of this object like the image below,


kjme12o1ha4l.png

And my code,
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 


My problem is with CodBarras Table and Unit of Measure Table. It says that is been updated or created but this table remains empty because Barcode message is empty.. Maybe I'm in the wrong trigger? I'm new in xml port and I'm a little confused of how to do this...

Another thing I've repaired is when the item is already created nothing changed.

My text file have this info,

"8020100172" "test" "UNI" "8020" "802010" "10" "10" "23" "23 EXIST" "FITO" "UNI" "1236547896541"

Answers

  • txerifftxeriff Member Posts: 500
    Hi, I would check the following:

    -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.

  • lubostlubost Member Posts: 627
    Your code:
    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.
Sign In or Register to comment.