Numeric field values using Web Services

tpbrophytpbrophy Member Posts: 12
edited 2009-10-03 in NAV Three Tier
Successfully used web service (NAV 2009 SP1) to add records to two tables. However, fields that are either date, integer or decimal are not being updated with the values assigned to the fields in the C# application.
Here is an extract of the code:
// Create an instance of Shopping Cart Header
ShoppingCartHeader SCHeader = new ShoppingCartHeader();
SCHeader.Shopping_Cart_No = "1234H";
SCHeader.Customer_Name = "Mary Jones";
SCHeader.Address = "1234 Bermuda Drive";
SCHeader.City = "Chicago";
System.DateTime orddate = new DateTime(2009, 9, 30);
SCHeader.Order_Date = orddate;
SCHeader.State = "IL";
SCHeader.ZipCode = "60609";
// Create an instance of Shopping Cart Line array
ShoppingCartLine[] SCLineArray = new ShoppingCartLine[4];
for (int i = 0; i < SCLineArray.Length; i++)
{
decimal j;
SCLineArray = new ShoppingCartLine();
SCLineArray.Shopping_Cart_No = SCHeader.Shopping_Cart_No;
SCLineArray.Line_No = (i+1) * 10000;
SCLineArray.Shopping_Cart_No += SCLineArray.Line_No.ToString();
j = (decimal)i+1;
SCLineArray.Product_ID = ((j*10000)+j).ToString();
SCLineArray.Product_Name = "Test Item " + j.ToString();
SCLineArray.Quantity = j.ToString();
SCLineArray.Unit_Price = (decimal)(j * 125);
SCLineArray.Extended_Price = j * SCLineArray.Unit_Price;
}
// Insert Shopping Cart Header
serviceHeader.Create(ref SCHeader);
for (int i = 0; i < SCLineArray.Length; i++)
{
serviceLine.Create(ref SCLineArray);
SCLineArray.Product_Name += "Again";
serviceLine.Update(ref SCLineArray);
}

Thanks in advance.

Comments

  • tlarsontlarson Member Posts: 27
    How are you adding records? Are you doing an Insert from C# or calling a command? Can you post some of the C# code you are using?

    Tim
  • kinekine Member Posts: 12,562
    The webservice is doing validation of field in order they are defined. Thus when validating field "No.", nearly all other fields are cleared. Do not forget about this...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • tpbrophytpbrophy Member Posts: 12
    Thanks, Kamil. That worked. However, when a table (e.g. Sales Line) has a multi-field primary key the "...No." field is populated on the insert and the secondary fields are populated on the update.
Sign In or Register to comment.