XMLport import problem

rokoroko Member Posts: 16
Hello.
I use XMLport-s to import data from XML files into Navision. Sometimes the data in the xml files already exists in Navision datrabase. How can I tell the XMLport to insert only the non-existing records in the database.
Thank you in advance.

Comments

  • rvduurenrvduuren Member Posts: 92
    Hello,
    How can I tell the XMLport to insert only the non-existing records in the database?

    Try: Make the SourceType Table Temporary, and then insert the records manually by code..
    CustRec := CustRecTmp;
    if NOT CustRec.insert then
      currXMLport.SKIP;
    
    Met vriendelijke groet, best regards,

    Rvduuren
  • rokoroko Member Posts: 16
    In which triger should I write this code?
  • DenSterDenSter Member Posts: 8,305
    XMLPorts only know how to create records, at least I have not been able to get one to update existing ones. The standard behavior seems to be that it leaves existing records alone, so you would have to program it to update them. New records should just go right in.
  • rokoroko Member Posts: 16
    I don't want to update the records, like the behavior of the Dataports. I just want not to import the records which are already in the database, because I get "Record already exists" error.
  • DenSterDenSter Member Posts: 8,305
    Then you use a record variable of the same type as the one you are importing, and you put something in the Import::OnBeforeInsertRecord trigger. Similar to Rik's example, but more like this:
    IF TempCustomer.GET(<ID value from the Dataitem>) THEN
      currXMLport.SKIP;
    
  • rokoroko Member Posts: 16
    I have thought about this solution, but I have 40 XMLports and if I have to add this code to every one, it will be very time consuming.
  • DenSterDenSter Member Posts: 8,305
    It's two lines of code, most of which you can copy/paste. You can do 40 XMLPorts in less than half an hour. What do you mean time consuming?
  • rokoroko Member Posts: 16
    Nevermind.
    Here is what I did for one ot the XMLports and it still gives me "Record already exists" error
    Documentation()
    
    OnInitXMLport()
    
    OnPreXMLport()
    
    OnPostXMLport()
    
    Document - Export::OnBeforePassVariable()
    
    Document - Import::OnAfterAssignVariable()
    
    ROW - Import::OnAfterInsertRecord()
    
    ROW - Export::OnPreXMLItem()
    
    ROW - Export::OnAfterGetRecord()
    
    ROW - Import::OnAfterInitRecord()
    
    ROW - Import::OnBeforeInsertRecord()
    IF UnitOfMeasure.GET("Unit of Measure".Code) THEN
      currXMLport.SKIP;
    
    Id - Import::OnAfterAssignField()
    
    Id - Export::OnBeforePassField()
    
    Name - Import::OnAfterAssignField()
    
    Name - Export::OnBeforePassField()
    
  • rokoroko Member Posts: 16
    rvduuren wrote:
    Hello,

    Try: Make the SourceType Table Temporary, and then insert the records manually by code..
    CustRec := CustRecTmp;
    if NOT CustRec.insert then
      currXMLport.SKIP;
    

    If I make the SourceType Table Temporary, I can't export enything, because the Temporary Source Table will be empty when exporting.
  • a_developera_developer Member Posts: 20
    roko wrote:
    Nevermind.
    Here is what I did for one ot the XMLports and it still gives me "Record already exists" error
    Documentation()
    
    OnInitXMLport()
    
    OnPreXMLport()
    
    OnPostXMLport()
    
    Document - Export::OnBeforePassVariable()
    
    Document - Import::OnAfterAssignVariable()
    
    ROW - Import::OnAfterInsertRecord()
    
    ROW - Export::OnPreXMLItem()
    
    ROW - Export::OnAfterGetRecord()
    
    ROW - Import::OnAfterInitRecord()
    
    ROW - Import::OnBeforeInsertRecord()
    IF UnitOfMeasure.GET("Unit of Measure".Code) THEN
      currXMLport.SKIP;
    
    Id - Import::OnAfterAssignField()
    
    Id - Export::OnBeforePassField()
    
    Name - Import::OnAfterAssignField()
    
    Name - Export::OnBeforePassField()
    

    I have the same problem. The workaround I did was to delete the existing record on the Import::OnBeforeInsertRecord() trigger.

    Did you find a better work-around?

    thanks
  • dennjelldennjell Member Posts: 1
    DenSter wrote:
    Then you use a record variable of the same type as the one you are importing, and you put something in the Import::OnBeforeInsertRecord trigger. Similar to Rik's example, but more like this:
    IF TempCustomer.GET(<ID value from the Dataitem>) THEN
      currXMLport.SKIP;
    


    Why the Command 'currXMLport.SKIP' does't work in the OnBeforeInsertRecord trigger?
    The XmlPorts inserts the dataitem, cause the Onafterinsert-Trigger runs.

    How can I solve the Problem without deleting before?
  • Ian_BachusIan_Bachus Member Posts: 21
    Hello. I'm having the same problem. The CurrXMLport.SKIP seems to be ignored in any trigger I try. The table is set to a temporary table but it's trying to insert the records anyway. Any ideas?
Sign In or Register to comment.