Blank record being inserted

I have a dataport with two fields variant code and status, when I run the dataport it is updating the correct record but it is inserting a blank records.

The key to the table is

Item Category Code, Product Group Code, Item No, Location Code, Variant Code

DP Fields / Globals: dvCode and dvStatus are both code 50

Code: OnAfterImportRecord

IF dvCode <> ‘’ THEN BEGIN

ior.SETFILTER(ior.“Item Category Code”, ior.“Item Category Code”);

ior.SETFILTER(ior.“Product Group Code”, ior.“Product Group Code”);

ior.SETFILTER(ior.“Item No.”, ior.“Item No.”);

ior.SETFILTER(ior.“Location Code”, ior.“Location Code”);

ior.SETFILTER(ior.“Variant Code”, dvCode) ;

IF ior.FINDFIRST THEN

BEGIN

IF dvStatus = ‘VALID’ THEN ior.Status := ior.Status::Valid;

IF dvStatus = ‘INVALID’ THEN ior.Status := ior.Status::Invalid;

ior.“Replication Counter” := ior.“Replication Counter” + 1;

ior.MODIFY();

END;

END ELSE;

How can I have it not insert that blank record? It shouldn’t insert a record if it does not find the Variant Code in my csv file.

You could set the target table as a variable, that way you can only insert a valid record.

What do you mean? I tried removing my data item, moved my code to the OnPostDataPort and OnPreDataPort and while it did not insert a record it did not update the record like it was doing.

I got it working. On the Data Item I set AutoSave and AutoUpdate to No and its now updating the right record and not inserting a blank record. Thanks for the help though!