Update data in NAV via C#

MajesticMajestic Member Posts: 10
edited 2013-10-14 in NAV Three Tier
Hello
ill try and make this short:
i have been trying to update some data in Nav from C#, but whatever i do i get errors:

my code Unit looks like this:
<operation name="OpdaterVogn">
<operation soapAction="urn:microsoft-dynamics-schemas/codeunit/BMG:OpdaterVogn" style="document"/>
<input name="OpdaterVogn">
<body use="literal"/>
</input>
<output name="OpdaterVogn_Result">
<body use="literal"/>
</output>
</operation>
afaik this is my method i need to use, to update the record in NAV. i need to update a "Vogn", and in my codeunit i get the following "class" i need to update with.
<schema elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-nav/xmlports/x78001">
<complexType name="VognType">
<sequence>
<element minOccurs="1" maxOccurs="1" name="Kode" type="string"/>
<element minOccurs="1" maxOccurs="1" name="RegNr" type="string"/>
<element minOccurs="1" maxOccurs="1" name="Beskrivelse" type="string"/>
<element minOccurs="1" maxOccurs="1" default="false" name="Spaerret" type="boolean"/>
</sequence>
</complexType>
<complexType name="Vogn" mixed="true">
<sequence>
<element minOccurs="1" maxOccurs="unbounded" name="Vogn" type="tns:VognType"/>
</sequence>
</complexType><element name="Vogn" type="tns:Vogn"/>
</schema>

Since i havent created the web service myself im provideing the above code in hopes that there might be something wrong with it. (created by a friend/college).

anyway, moveing on to C#, i can get the data over to C# and review it. Now i want to update a "vogn" with the method.

at the moment my code looks like this:
Vogn vogneNy = new Vogn();
            VognType vognNy = new VognType();

            ws.SendVogn("BMG 2013", false, ref vogneNy);
            vogneNy.Vogn1[0].Beskrivelse = "lol";
            ws.OpdaterVogn("BMG 2013", vogneNy);
i get the following error: The Vogn already exists. Identification fields and values: Kode='FF1D57CC0

i have exposed the NAV service as a Web Reference.

im running out of patience, and hopefully one of you guys can help me here ](*,)

Answers

  • MajesticMajestic Member Posts: 10
    quick update:

    i try and add the data to a list and thereafter send that to NAV
    Vogn vogneNy = new Vogn();
                VognType vognNy = new VognType();
                
                List<VognType> list = new List<VognType>();
                vognNy.Kode = kode; // string value to update
                vognNy.Beskrivelse = beskrivelse; // string value to update
                vognNy.RegNr = regnr; // string value to update 
                vognNy.Spaerret = spaerret; // Bool value to update 
    
                list.Add(vognNy);
                vogneNy.Vogn1 = list.ToArray();
                ws.OpdaterVogn("BMG 2013", vogneNy);
    

    new Error: {"The Element <Kode> is expected by Min Occurs value: Once. Element received: <>."}
  • Wisa123Wisa123 Member Posts: 308
    Hi,

    I personally dont really like the list approach because nav often has its difficulties with it in my experience.

    Frankly, there seems to be something wrong with the Codeunit.

    Best of Luck

    Wisa
    Austrian NAV/BC Dev
  • MajesticMajestic Member Posts: 10
    there was indeed something wrong with the codeUnit, its all fixed now :)
Sign In or Register to comment.