How do I validate during Dataport import?

jfrizellejfrizelle Member Posts: 5
Hi,

First post, new to Navision.

I've imported a file of Postcodes using a dataport.

Now I need to import a file of customers, and as I import I want to check that the postcode on the customer record exists in the Postcodes table.

Simple, eh?

But how do I do it???

I've created 'test' tables to mess around with, and here's what I've tried so far...

I've set the TableRelation property on the "Cust Postcode" field to TEST_Postcodes.Postcode, and ValidateTableRelation is set to YES, but when I ran the Dataport it imported customers with non-existant postcodes.

Then I created a record variable and entered code in the OnInsert trigger for the TEST_Customers table as follows :

IF NOT(recTest_Postcodes.GET("Cust Postcode")) THEN
ERROR('Invalid Postcode');

Same thing, still imported customers with invalid data.

](*,) What to do??

Thanks a lot for any help!
J.

Comments

  • DenSterDenSter Member Posts: 8,307
    I think I would try the same code in the OnAfterImport trigger of your dataport. You can simply do:
    recTest_Postcodes.GET("Cust Postcode");
    
    because if there is no such postcode, it will error out all by itself.

    By the way, the syntax:
    IF NOT(recTest_Postcodes.GET("Cust Postcode"))
    
    is not correct. The right way to write the lines you mention is this:
    IF NOT recTest_Postcodes.GET("Cust Postcode") THEN
      ERROR('Invalid Postcode');
    
    But again, just the GET should be enough.
  • jfrizellejfrizelle Member Posts: 5
    Thank you very much Daniel!

    I wanted the custom error so that I could specify which customer record had the invalid postcode - it's working fine now.

    Rgds,
    Jennie.
  • DenSterDenSter Member Posts: 8,307
    That is an excellent reason for doing it that way then :) Glad you got it to work.
Sign In or Register to comment.