Options

XMLPort import, Tempory table, CurrXMLPort.SKIP

Ian_BachusIan_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!

Answers

  • Options
    DenSterDenSter Member Posts: 8,304
    Have you tried other triggers?
  • Options
    Ian_BachusIan_Bachus Member Posts: 21
    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. :-k
  • Options
    activ8activ8 Member Posts: 25
    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.
  • Options
    Ian_BachusIan_Bachus Member Posts: 21
    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 :D 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 :mrgreen: .
  • Options
    Ian_BachusIan_Bachus Member Posts: 21
    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/
Sign In or Register to comment.