Modify existing data in table when importing from XML

Tiwaz
Member Posts: 98
Hi everyone 
I created an XMLPort which imports data from XML to a table in my table.
It only adds new lines in table when importing which is fine until it tries to import an entry from XML which has the same Serial No. (primary key) as an entry in my table when it returns error.
I want to add CONFIRM window and modify existing data.
For example, I have Car Serial No., Model and License Plates fields in my table.
When I import a car with same serial no. but different License plates it returns error since it tries to add new line.
I hope you get what I need
THANKS!

I created an XMLPort which imports data from XML to a table in my table.
It only adds new lines in table when importing which is fine until it tries to import an entry from XML which has the same Serial No. (primary key) as an entry in my table when it returns error.
I want to add CONFIRM window and modify existing data.
For example, I have Car Serial No., Model and License Plates fields in my table.
When I import a car with same serial no. but different License plates it returns error since it tries to add new line.
I hope you get what I need

THANKS!
0
Best Answer
-
As I said, It is unique but sometimes, you wish to import data connected with serial no. that already exists in the table but something, ex:. car colour is different so that needs to be updated.
But I figured it out. I set AutoUpdate property of table element to Yes, and it updates fields connected with serial no. that already exists.5
Answers
-
You can write your code in OnBeforeInsertRecord function in XML port to check if the Serial No. exists already. If the Serial No. exists then you can choose to skip the record by using currXMLport.SKIP or you can write a code to modify the record.1
-
Apparently the serial no. is not unique, and therefor not the right choice for a primary key. Either you need to extend the primary key with the brand of the car, or the license-plate, but this will influence existing code that works with the file!
You can also force the primary key to be unique by adding a consecutive number as primary key, and use the serial no. as secondary key.IF User.Loves('Edo') THEN ok() ELSE currReport.genSkip;0 -
As I said, It is unique but sometimes, you wish to import data connected with serial no. that already exists in the table but something, ex:. car colour is different so that needs to be updated.
But I figured it out. I set AutoUpdate property of table element to Yes, and it updates fields connected with serial no. that already exists.5
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions