Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Update and insert via xmlport

Posted on by Microsoft Employee

Hi experts,

 

 

 

I got task create web service which  update specific record via xmlport. This is first think  what I try to do  in Dynamic nav.I don’t  know is this right way to do.

Inserting new record in table works fine, but even I try to update old  record I get this error

"The Sales Header Exists. Identification fields and values:"

But still record is updated.

I write following code in xmlport:

 

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<Header>
	<SalesNo>16000604</SalesNo>
	<CustomerNo>POS</CustomerNo>
	<ReceiptNo>1234567890</ReceiptNo>
	<type>Order</type>
	<ReceiptDate>31.05.10</ReceiptDate>
	<Lines>
		<RowNro>10000</RowNro>
		<Type>Item</Type>
		<ProductNro>117648</ProductNro>
		<Title>somethink123</Title>
		<DocumentType>Order</DocumentType>
		<documentno>16000604</documentno>
	</Lines>
	<Lines>
		<RowNro>10001</RowNro>
		<Type>Item</Type>
		<ProductNro>117648</ProductNro>
		<Title>somethink1</Title>
		<DocumentType>Order</DocumentType>
		<documentno>16000604</documentno>
	</Lines>
</Header>


Document Type"::Order);

    IF (SaleHeader.FIND('-')) THEN BEGIN

       SaleHeader."External Document No.":= '0987654321';
      SaleHeader."Order Date":= "Sales Header"."Order Date";
      SaleHeader."Sell-to Customer No.":= "Sales Header"."Sell-to Customer No.  
      SaleHeader."Sell-to Address 2":='TESTING TESTING!';
      SaleHeader.MODIFY;
      END;

   COMMIT;

The  key idea is frist check if record is in table, if not then insert it in other case we update exiting record. My xml look like this:

*This post is locked for comments

  • Suggested answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: Update and insert via xmlport

    i did some tests.

    everytime you run gXMLP.IMPORT; the loaded sales order will be imported, but it is not possible, because it already exists, so you get that error message.

    i removed the gXMLP.IMPORT; command, then retested and got a different error: the connection is closed. the nav service instance was killed, when running the update webservice call. the reason seems to be using instream in the update function, which is then published as web method of the web service. so better rewrite your code.

    write a function to load the sales order, then a second function to update the sales order. call both functions then in your c# code. do not use instreams in these functions.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update and insert via xmlport

    Here is c# code

               using (var pd = new PdDataServices())

               {

                   pd.Url = webserviceUrl;

                   pd.UseDefaultCredentials = true;

                   pd.AllowAutoRedirect = true;

                   pd.PreAuthenticate = true;

                   pd.ModifyRecord(ref header);

               }

             //  return SaleHeader;

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update and insert via xmlport

    Here is code unit code


    gFile.OPEN(lCopyFromFile);
    gFile.CREATEINSTREAM(gInStream);      //Readdata from xml file
    gXMLP.SETSOURCE(gInStream);//gXMLP.IMPORT;
    gXMLP.IMPORT;
    gFile.CLOSE;

  • keoma Profile Picture
    keoma 32,675 on at
    RE: Update and insert via xmlport

    please publish the code where you call the webservice (c# ?).

    what do you do with the second code sample ?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans