OData NAV 2013 R2 sav.changes() error

MBrodie1979MBrodie1979 Member Posts: 21
edited 2015-04-01 in NAV Three Tier
Hello.

Im trying to follow this article:

https://msdn.microsoft.com/en-us/library/hh166960%28v=nav.71%29.aspx?f=255&MSPPError=-2147217396

Here is my code, bu it keeps failing on nav.savechanges() it says "An error occurred while processing this request.". Any ideas? Does it have to do with the fact that by default the page opens in View mode?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NAVCustomers.ServiceReference1;


namespace NAVCustomers
{
    class Program
    {

        static void Main(string[] args)
        {
            NAV nav = new NAV(new Uri("http://localhost:7048/DynamicsNAV/OData/Company('CRONUS%20International%20Ltd.')"));
            nav.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; 

              Console.WriteLine("Printing list of current customers:");
              PrintCustomersCalledCust(nav);
              Console.WriteLine("Adding new customer.");
              Customer newCustomer = new Customer();
              newCustomer.No = "10001";
              newCustomer.Name = "Customer Name";
              nav.AddToCustomer(newCustomer);
              nav.SaveChanges();
              Console.WriteLine("Printing list of current customers:");
              PrintCustomersCalledCust(nav);
              newCustomer.Name += "Changed";
              nav.UpdateObject(newCustomer);
              nav.SaveChanges();
              Console.WriteLine("Printing list of current customers:");
              PrintCustomersCalledCust(nav);
        }

        private static void PrintCustomersCalledCust(NAV nav)
        {
            var customers = from c in nav.Customer
                            where c.Name.StartsWith("Cust")
                            select c;
            Boolean customerFound = false;

            //foreach (Customer customer in customers)
           // {
           //     customerFound = true;
           //     Console.WriteLine("No.: {0} Name: {1}", customer.No, customer.Name);
           // }

            if (!customerFound)
            {
                Console.WriteLine("There are no customers that start with 'Cust'.");
            }
        }


      }
}
Sign In or Register to comment.