Create Dataport with validation ?

I need to update gross weight and net weight in the Item table and need to ask the system to check the validity of the item codes (in the speadsheet) before the data is imported into the table and asks the system skip to the next row if the item code is not found in the table.

Please help me how to create the data port.

Many thanks.

ZEN [:)]

If you change the Autosave property to No on the dataport it will not add items or change unless they already exist. Would this do what you want, or do you want to do additional checks and processing before you decide to update the record?

On second thought, too make it easier :

create a global variable Item2

then add the below code to the onafterimportrecord trigger"

Item - OnPreDataItem()

Item - OnBeforeExportRecord()

Item - OnAfterExportRecord()

Item - OnBeforeImportRecord()

Item - OnAfterImportRecord()
IF NOT item2.GET(“No.”) THEN CurrDataport.SKIP;

Item - OnPostDataItem()

Hi John,

Thank you for reply.

I have tested the coding. It works perfectly.

Actually, after importing process, we also like to know:

  1. How many and which items that successfully imported?

  2. How many and which items that unsuccessfully imported?

Thanks,

ZEN [:D]

Add two additional global variables type Integer

CountGood, CountBad

change/add code in the below triggers:

Item - OnPreDataItem()

Item - OnBeforeExportRecord()

Item - OnAfterExportRecord()

Item - OnBeforeImportRecord()

Item - OnAfterImportRecord()
IF NOT item2.GET(“No.”) THEN BEGIN
CountBad +=1;
CurrDataport.SKIP;
END;
CountGood +=1;

Item - OnPostDataItem()

Dataport - OnInitDataport()

Dataport - OnPreDataport()

Dataport - OnPostDataport()
MESSAGE(‘Items Changed: %1 Items Skipped: %2’,CountGood,CountBad);

John, you are awesome! [Y]

One last question; could we send those failed items into .txt file (just captured the item code and desc.)?

Thanks,

ZEN [:)]

Add these fields and the additional code and see if that is what you want.

Name DataType Subtype Length
item2 Record Item
CountGood Integer
CountBad Integer
TextLine Text 200
FileNameOut File
InDescription Text 30

Dataport - OnInitDataport()

Dataport - OnPreDataport()
CLEAR(FileNameOut);
FileNameOut.TEXTMODE := TRUE;
IF NOT FileNameOut.CREATE(‘C:\TEMP\Errors.txt’) THEN BEGIN
ERASE(‘C:\TEMP\Errors.txt’);
FileNameOut.CREATE(‘C:\TEMP\Errors.txt’);
END;

Dataport - OnPostDataport()
FileNameOut.CLOSE;
MESSAGE(‘Items Changed: %1 Items Skipped: %2’,CountGood,CountBad);

Item - OnPreDataItem()

Item - OnBeforeExportRecord()

Item - OnAfterExportRecord()

Item - OnBeforeImportRecord()

Item - OnAfterImportRecord()
IF NOT item2.GET(“No.”) THEN BEGIN
CountBad +=1;
TextLine :=“No.”+’,’+InDescription;
FileNameOut.WRITE(TextLine);
CurrDataport.SKIP;

END;
CountGood +=1;

John,

I am highly appreciating your helps; two thumbs up from me to you [Y] [Y]. You are great!!!

I will figure out myself why the result of the.txt file is empty.

Thank you very much.

ZEN [:D]

Just let me know if you don’t figure it out, I will help you !!

I got it John; I missed one line of your codings. [:$]

Thank you.