Use a variable to export a NotBlank field

Situation: A dataport is importing (non-primary) field F, and F has NotBlank = Yes. However, the data you are importing could have records with blank F. Error: If you just include F in the Dataport Fields, you will get an error like “This field cannot be blank”. Explanation: NotBlank creates an error only when F is explicitly assigned to be blank. It will allow a record to be created where F is blank by default because it is never assigned a value. What you cannot do is create a record with non-blank F, and then blank it later on. (Remember that F is not in the primary key). A dataport, however, automatically assigns each value in the import file to the associated field in the field list, creating an error when some record has blank F. Solution: Do not include F in the Dataport Fields. Instead, use some variable Fvar as the source expression in the Dataport Fields, and add the following code in the OnAfterImportRecord:

quote:

IF Fvar <> ‘’ THEN F := Fvar;

Just in case you use the same dataport for exporting too, put the following code in OnBeforeExportRecord:

quote:

Fvar := F;