how to update the information using XMLPorts

chandrurecchandrurec Member Posts: 560
edited 2013-03-05 in NAV Three Tier
Hi all,

I have created a xmlport to import customer records to navision. for this the first time when i import the file , the customer need to be inserted and from the next time , it needs to be updated. So I have written the code as below in onafterimport trigger in xmlport.


IF NOT CustRec.GET(Customer."No.") THEN BEGIN
Customer."No." := Customer."No.";
Customer.Name := Customer.Name;
Customer."Search Name" := Customer."Search Name";
Customer."Name 2" := Customer."Name 2";
Customer.Address := Customer.Address;
Customer.MODIFY(TRUE);
END
ELSE
Customer.INSERT(TRUE);


but still I am getting the error customer record already exists.

If anyone knows the solution for the above mentioned scenario, kindly let me know.

Thanks in advance.

Regards,
chandru.

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Instead of using Table's field in the XMLPort field, define global variables and use them in XMLPort as Text.

    Check if there is any record with these values of primary key, if yes then assign the field values from the variables and at the end write MODIFY
    Or
    If record doesn't exist then assign values to field from these variable and write INSERT.
  • Wisa123Wisa123 Member Posts: 308
    IF NOT CustRec.GET(Customer."No.") THEN BEGIN
    Customer."No." := Customer."No.";
    Customer.Name := Customer.Name;
    Customer."Search Name" := Customer."Search Name";
    Customer."Name 2" := Customer."Name 2";
    Customer.Address := Customer.Address;
    Customer.MODIFY(TRUE);
    END
    ELSE
    Customer.INSERT(TRUE);
    

    So if theres no Record then you will modify the non existing record ?
    And if there is a Record then you will insert a Blank one ?
    Your Code says that ...

    just remove the NOT in your IF-Clause and youll be fine !

    €: watch mohanas post above for a cleaner solution
    Austrian NAV/BC Dev
  • chandrurecchandrurec Member Posts: 560
    Hi Wisa123 ,

    Even if i remoce the not , still I am getting a error as follows.

    The XML Parser return the following fatal error:
    A document must contain exactly one root element.

    Line Number = 9 Column Number = 10

    If you have any idea, kindly let me know.

    Thanks in advance.

    Regards,
    chandru.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Can you show us the screenshot of XMLport in design mode?
Sign In or Register to comment.