Sales Orders by WebService

gianmariaigianmariai Member Posts: 7
edited 2015-04-01 in NAV Three Tier
Hello All,
I'm so new to NAV, but got skills in .net development.

I've tried with succes to create new customers using a Page WebService (object ID 21), usng the following code:
            ODataService.Customer c = ODataService.Customer.CreateCustomer("Gianmaria");
            c.Name = "AAA New Company";
            c.Address = "A Road Name, House Number 5";
            c.City = "Rome";
            c.Contact = "Mark Jacobs";
            c.Country_Region_Code = "IT";
            c.E_Mail = "mark@nowhere.it";
            c.No = "101";
            

            ODataService.NAV nav = new ODataService.NAV(new Uri("http://win-o490:7048/DynamicsNAV71/OData/"));

            nav.AddToCustomer(c);
            ICredentials credentials = new NetworkCredential("username", "password");

            nav.Credentials = credentials; 

            try
            {
                System.Data.Services.Client.DataServiceResponse res = nav.SaveChanges();
            }
            catch (DataServiceRequestException ex)
            {
                Exception innerEx = ex.InnerException;
                System.Diagnostics.Trace.WriteLine(ex.Message + "\n" + innerEx.Message);
            }

Everything works fine, even if I'm not sure this is the right way to do. Anyway.. my problem is on Orders. I've tried to apply same logic on Order creation. I exposed NAV data by web service, again as Page and using object id 48. In code i wrote:
ODataService.SalesOrder order = ODataService.SalesOrder.CreateSalesOrder("Order", "1500", 1);
            order.Sell_to_Customer_No = "101";
            nav.AddToSalesOrder(order);
           

            try
            {
                System.Data.Services.Client.DataServiceResponse res = nav.SaveChanges();
            }
            catch (DataServiceRequestException ex)
            {
                Exception innerEx = ex.InnerException;
                System.Diagnostics.Trace.WriteLine(ex.Message + "\n" + innerEx.Message);
            }

When I execute code i receive the followin message:
<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="it-IT">An error occurred while processing this request.</m:message><m:innererror><m:message>The underlying application page is not editable.</m:message><m:type>Microsoft.Dynamics.Nav.Service.ODataServiceProvider.ODataException</m:type><m:stacktrace></m:stacktrace></m:innererror></m:error>

It seem i'm violating some rule on insert.. or I'm completely wrong this time.. someone can help? Someone done same thing using Visual Studio to attach NAV WS?

my best regards,
Gianmaria

Comments

  • SaalekSaalek Member Posts: 181
    Hi

    Check in your Nav Page 48, if the properti EDITABLE of any of the fields you are filling (Document Type, No., ...) is set to FALSE.
    If you are inserting information from Web Services, this fields must be editable.

    Bye
  • gianmariaigianmariai Member Posts: 7
    Thank you for your answer, i founf the solution. I used a different object, the page object 42 and it worked. I think that the object 48 was a read only object.
    If i can find somewhere a complete listing of this object with some information it will be very usefull.
    thank you again.

    If someone need the code i used to insert orders and customers i can post.

    Regards,
    gianmaria
  • MBrodie1979MBrodie1979 Member Posts: 21
    Hi Gianmaria.

    I like your post.

    You mentioned if someone wanted the files you could sent them, may I please have these i am trying to learn how to talk to NAV using C#?
Sign In or Register to comment.