Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

OData web services page insert -- return ID

Posted on by Microsoft Employee

I am inserting new data to a NAV page via the OData web services.

One test i am attempting is inserting a sales invoice, and a related sales line.

The sales invoice header inserts just fine. 

But i was wondering:

1. how i can get the document no  from that new sales invoice record? 

2. The sales invoice line i add doesn't get inserted -- no error, i just don't know if it is linked properly to the parent sales invoice record

Integration_Sales_Invoice newSalesInvoice = new Integration_Sales_Invoice();                
                    newSalesInvoice.Bill_to_Customer_No = "1113";
                    newSalesInvoice.Bill_to_Name = "Test BillTo";
                    newSalesInvoice.Document_Date = Convert.ToDateTime("2016-03-21");
                    newSalesInvoice.Due_Date = Convert.ToDateTime("2016-04-22");                   
                    newSalesInvoice.Shipment_Date = Convert.ToDateTime("2016-03-22");
                    newSalesInvoice.Sell_to_Customer_No = "1113";
                    newSalesInvoice.Sell_to_Customer_Name = "Test Customer";

                nav.AddToIntegration_Sales_Invoice( newSalesInvoice);

               
                
                Integration_Sales_InvoiceSalesLines newSalesInvoiceLine = new Integration_Sales_InvoiceSalesLines();
                    nav.AddToIntegration_Sales_InvoiceSalesLines(newSalesInvoiceLine);              
                    newSalesInvoiceLine.Type = "Resource";
                    newSalesInvoiceLine.Description = "Scheduled Work";
                    newSalesInvoiceLine.Quantity = Convert.ToDecimal(2.5);
                    newSalesInvoiceLine.Unit_of_Measure_Code = "HR";
                    newSalesInvoiceLine.Unit_Price = Convert.ToDecimal(125.00);
                    newSalesInvoiceLine.Line_Amount = Convert.ToDecimal(312.50);
                    newSalesInvoiceLine.Amount_Including_VAT = Convert.ToDecimal(312.50);
                    newSalesInvoice.Integration_Sales_InvoiceSalesLines.Add(newSalesInvoiceLine);  
                    

                nav.SaveChanges();

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: OData web services page insert -- return ID

    hi TDawg,

    the reason is you publish a subform but in that subform there's document field and line no.

    you can add these 2 fields to subform and set the visible property to 'false'

    Cheers

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: OData web services page insert -- return ID

    I was mistaken in my original question --- the line was erroring when saving.  it stated it did not have a document no.     So...   if i choose to use the auto id creation for the sales invoice --- can i get back that ID?    Or... is there a way to generate a new ID that i can then assign to the sales invoice, and subsequent sales invoice lines?

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: OData web services page insert -- return ID

    Have you checked in the sales line table, if the record is inserted or not?

    Also try with manual Document No. and see the result.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans