XMLPort import, Tempory table, CurrXMLPort.SKIP

Ian_Bachus
Member Posts: 21
Hello all. I've searched these forums hard for an answer to my problem but I could find the answer to one little detail with my problem.
The Setup:
I have an XMLPort that reads in an XML doc that has a duplicate entry. In my XMLport I have one table which is a "Temporary" table. On the OnBeforeInsertRecord trigger of the table I search the record to see if it exists. I am able to successfully locate the existing record and I call a CurrXMLport.SKIP and the CurrXMLport.SKIP does execute but Navision tries to insert the record anyway. Any ideas as to why it inserts regardless of the CurrXMLport.SKIP? If not, how can I make it so that it doesn't insert.
Below is code from my OnBeforeInsertRecord trigger.
IF Rec.GET(field.variable,field.variable,field.variable) THEN BEGIN
MESSAGE('THIS RECORD ALREADY EXISTS');
currXMLport.SKIP;
END;
I can see the dialog pop up when a duplicate is found and the skip executes but then I get a Navision error that the entry already exists and the program just dies ](*,) .
Any ideas?
Thanks!
The Setup:
I have an XMLPort that reads in an XML doc that has a duplicate entry. In my XMLport I have one table which is a "Temporary" table. On the OnBeforeInsertRecord trigger of the table I search the record to see if it exists. I am able to successfully locate the existing record and I call a CurrXMLport.SKIP and the CurrXMLport.SKIP does execute but Navision tries to insert the record anyway. Any ideas as to why it inserts regardless of the CurrXMLport.SKIP? If not, how can I make it so that it doesn't insert.
Below is code from my OnBeforeInsertRecord trigger.
IF Rec.GET(field.variable,field.variable,field.variable) THEN BEGIN
MESSAGE('THIS RECORD ALREADY EXISTS');
currXMLport.SKIP;
END;
I can see the dialog pop up when a duplicate is found and the skip executes but then I get a Navision error that the entry already exists and the program just dies ](*,) .
Any ideas?
Thanks!
0
Answers
-
-
Just for argument sake, I put a CurrXMLport.SKIP in every trigger and it still tried to insert the record! I must be missing something. :-k0
-
Maybe something like this ?
You have to do this on the Import::OnAfterInsertRecord() trigger of
the temp table record.
And if you insert more then 1 record you have to loop your temp
table plus the property MaxOccurs must be Unbounded.
In this case i will check if the record allready exists not using the primarykey
of the table but the "external documetn No." because that's the
unique number of the customers Document.
TempHeader - Import::OnAfterInsertRecord()
CLEAR(recHeader);
recHeader.SETCURRENTKEY("External Document No.");
recHeader.SETRANGE("External Document No.",TempHeader."External Document No.");
IF NOT recHeader.FIND('-') THEN BEGIN
recHeader.TRANSFERFIELDS(TempHeader);
IF recHeader.INSERT(TRUE) THEN BEGIN
...
...
...
END ELSE BEGIN
// Error Order Header not inserted
END;
END ELSE BEGIN
// Error Order already Exists
END;
Maybe something like this ?
You have to do this on the Import::OnAfterInsertRecord() trigger of
the temp table record.
And if you insert more then 1 record you have to loop your temp
table plus the property MaxOccurs must be Unbounded.
In this case i will check if the record allready exists not using the primarykey
of the table but in this case "the external documetn No." because that's the
unique number of the customers Document.
TempHeader - Import::OnAfterInsertRecord()
CLEAR(recHeader);
recHeader.SETCURRENTKEY("External Document No.");
recHeader.SETRANGE("External Document No.",TempHeader."External Document No.");
IF NOT recHeader.FIND('-') THEN BEGIN
recHeader.TRANSFERFIELDS(TempHeader);
IF recHeader.INSERT(TRUE) THEN BEGIN
...
...
...
END ELSE BEGIN
// Error Order Header not inserted
END;
END ELSE BEGIN
// Error Order already Exists
END;
CLEAR("TempHeader);
And if this is not what you are looking for, you can always
base your import on a integer table en use elements with source type text.
And if this is not what you are looking for, you can always
base your import on a integer table en use elements with source type text.0 -
Thank you for your solution! I just attacked this another route however. One thing I failed to mention was that this XMLport is run by a NAS so we can never have the error happen because the import will die. Anyway, since I could not get the Temporary table to work..I could actually modify the record before the XMLPort inserted it automatically but I could not stop it from inserting
so I created a physical table in the database (consumed a table ID) with the exact same structure except that I created an Integer primary key. So I basically insert all the records into this new physical "temporary" table first, spin through the records and check for duplicates before I insert them into the "live" table. I know it adds an extra step of processing but it seemed like it was the only way I could get it to work. I've got some more testing to do so I'll post back if this actually went into production or not. I think it will though
.
0 -
Ok! My fix went into production and it works great! Funny how I could easily modify the records before the XMLPort would insert them but I could not stop them from being inserted! I even tried the Temporary option and changing all the elements to text and the XMLPort would just try to insert a blank record and blow up. So this little solution works. It may not be the best way but it does the trick. \:D/0
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