Options

Issue with XMLPort importing CSV file

JustAnotherNavUserJustAnotherNavUser Member Posts: 7
edited 2013-05-09 in NAV Three Tier
Morning all,

I've been beating myself up over this for a while.

I'm updating an XMLPort for NAV 2013 which will be importing a CSV file. All this is fine.

Now, the issue I'm coming across is that the client is wanting to ensure that current records don't already exist in this destination table when importing the file. The import file is of course allowed to contain many instances of the same Key 1 (below) as this is being imported to create a Warehouse Shipment document.

So, Key 1 will define that it's a line (and header will be created automatically) and can obviously be present on multiple lines on the import document. The bit that's going wrong is that Key 1 may well appear 1 week down the line in a different file. In this instance it must error. The import is coming to a staging table prior to a secondary routine creating the Warehouse shipments.

The file looks something like this:
Header 1 | Header 2 | Header 3 | Header N
Key 1    | Value 1    | Disregard | This
Key 1    | Value 2    | It is        | unrequired
Key 2    | Value 1    | for this   | problem
...
Key N    | Value N    | Still       | unimportant.

The issue I'm having with my XMLport is that when I attempt to implement the check of 'Does Key 1 exist in the table already' it's falling over on line 2 of the import file.

However, upon throwing my ERROR() the first line is not visible in the database, as I'd expect.

With this in mind if I have something like this
MyXMLPort
  MyTable      Element       Table      <MyTable><MyTable>
    KeyInImportFile            Element       Text        KeyInImport File                       //I've tried this being a source type of 'Field' too.

and then;
SecondInstanceOfMyTable.SETRANGE(Key, KeyOnTable)
IF SecondInstanceOfMyTable.FINDSET THEN
  ERROR(); //already exists.

How am I able to circumvent this and allow multiple occurrence of 'Key N' within the file and only check for duplicates that are already existing and have been committed to the database table?

Cheers.

EDIT: Never mind, complete balls-up on my side, after a bit of Rubber Duck Debugging I worked out the system was working correctly and I'd need an additional filter.

Answers

Sign In or Register to comment.