Wrong date Updation in webservices

Ashish_GuptaAshish_Gupta Member Posts: 56
edited 2009-10-05 in NAV Three Tier
I am using webservices to create a record in NAV Customized table having a primary key and couple of text fields and couple of dates. The primary key and the text fields are getting created correctly but the date field is getting intialized to 01/01/01. When I am modifying the record the date is correctly updated. I have written the same code in both the functions but ](*,)

My code is as follow

Create Code:
protected void Btn_InsertStream_Click(object sender, EventArgs e)
    {
        StreamList_Service stream = new StreamList_Service();
        stream.UseDefaultCredentials = true;

        StreamList newstream = new StreamList();
        newstream.Code = txt_code.Text;
        newstream.Description = Txt_Description.Text;
        newstream.Description_2 = Txt_Description2.Text;
        newstream.Start_Date = Convert.ToDateTime(Txt_startdate.Text);
        newstream.End_Date = Convert.ToDateTime(Txt_Enddate.Text);
        stream.Create(ref newstream);
        Response.Redirect("Streams.aspx");
    }
update code
protected void btn_Update_Click(object sender, EventArgs e)
    {
        StreamList_Service stream = new StreamList_Service();
        stream.UseDefaultCredentials = true;

        StreamList newstream = new StreamList();
        newstream.Code = txt_code.Text;
        newstream = stream.Read(newstream.Code);
        newstream.Description = Txt_Description.Text;
        newstream.Description_2 = Txt_Description2.Text;
        newstream.End_Date = Convert.ToDateTime(Txt_Enddate.Text);
        newstream.Start_Date = Convert.ToDateTime(Txt_startdate.Text);
        stream.Update(ref newstream);
        Response.Redirect("Streams.aspx");
    }

Any help will be greatly appreciated.
Ashish Gupta
Navision Technical Consultant

Answers

  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    You need to set

    newstream.Start_DateSpecified = true;
    newstream.End_DateSpecified = true;

    when creating the record.

    These variables tells Visual studio which values it should include when sending data over the wire to NAV.
    Reason why your update works is, that when you get the record back you get all fields (and all xxxSpecified = true).
    xxxSpecified does not exist for string fields - these fields can be set to NULL in order to specify that you don't want it send over the wire.
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • kinekine Member Posts: 12,562
    freddy.dk wrote:
    You need to set

    newstream.Start_DateSpecified = true;
    newstream.End_DateSpecified = true;

    when creating the record.

    These variables tells Visual studio which values it should include when sending data over the wire to NAV.
    Reason why your update works is, that when you get the record back you get all fields (and all xxxSpecified = true).
    xxxSpecified does not exist for string fields - these fields can be set to NULL in order to specify that you don't want it send over the wire.

    Very insteresting... is this described somewhere in the documentation? ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    Probably in the Visual Studio documentation as these variables determines what will be send over the wire to Web Services from your C# app.
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
Sign In or Register to comment.