ODATA Add Purchase Invoice Line

PatrickSmitsPatrickSmits Member Posts: 2
edited 2014-07-07 in NAV Three Tier
Hi

I recently started using the Nav ODATA Webservices. They work fine for the sales invoices. I can add a sales invoice and add lines to the sales invoice using the ODATA POST method. However when I want to add a purchase invoice line I get errors. When I add a new Purchase Invoice, the invoice is added and I get the invoice number returned. I use that invoice number to add purchase invoice lines according to the XML as you can see below. However this returns the error:

Document No. must have a value in Purchase Line: Document Type=Invoice, Document No.=, Line No.=0. It cannot be zero or empty

This is strange because the document no is provided in the XML and line No. is not the number I entered. Is this a bug Nav?

Patrick

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom&quot; xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices&quot; xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"&gt;
<category term="NAV.Purchase_InvoicePurchLines" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme&quot; />
<id />
<title />
<updated>2014-06-13T08:40:50Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:Document_Type>Invoice</d:Document_Type>
<d:Document_No>1009</d:Document_No>
<d:Line_No m:type="Edm.Int32">10000</d:Line_No>
<d:Type>Item</d:Type>
<d:No>1001</d:No>
<d:Cross_Reference_No />
<d:IC_Partner_Code />
<d:IC_Partner_Ref_Type xml:space="preserve"></d:IC_Partner_Ref_Type>
<d:IC_Partner_Reference />
<d:Variant_Code />
<d:Nonstock m:type="Edm.Boolean">false</d:Nonstock>
<d:Gen_Bus_Posting_Group>EXPORT</d:Gen_Bus_Posting_Group>
<d:Gen_Prod_Posting_Group>DET.HANDEL</d:Gen_Prod_Posting_Group>
<d:VAT_Bus_Posting_Group>EXPORT</d:VAT_Bus_Posting_Group>
<d:VAT_Prod_Posting_Group>BTW19</d:VAT_Prod_Posting_Group>
<d:Description>Tourfiets</d:Description>
<d:Description_2 />
<d:Certificate_Required m:type="Edm.Boolean">false</d:Certificate_Required>
<d:Certificate_Received m:type="Edm.Boolean">false</d:Certificate_Received>
<d:Certificate_Receipt_Date m:type="Edm.DateTime">0001-01-01T00:00:00</d:Certificate_Receipt_Date>
<d:Return_Reason_Code />
<d:Location_Code />
<d:Bin_Code />
<d:Quantity m:type="Edm.Decimal">1</d:Quantity>
<d:Unit_of_Measure_Code>STUKS</d:Unit_of_Measure_Code>
<d:Unit_of_Measure>Piece</d:Unit_of_Measure>
<d:Quantity_Price_UoM m:type="Edm.Decimal">0</d:Quantity_Price_UoM>
<d:Price_Unit_of_Measure_Code />
<d:Price_Unit_of_Measure />
<d:Direct_Unit_Cost_Price_UoM m:type="Edm.Decimal">0</d:Direct_Unit_Cost_Price_UoM>
<d:Direct_Unit_Cost m:type="Edm.Decimal">0</d:Direct_Unit_Cost>
<d:Indirect_Cost_Percent m:type="Edm.Decimal">0</d:Indirect_Cost_Percent>
<d:Unit_Cost_LCY m:type="Edm.Decimal">350.595</d:Unit_Cost_LCY>
<d:Unit_Price_LCY m:type="Edm.Decimal">4000</d:Unit_Price_LCY>
<d:Line_Amount m:type="Edm.Decimal">0</d:Line_Amount>
<d:Line_Discount_Percent m:type="Edm.Decimal">0</d:Line_Discount_Percent>
<d:Line_Discount_Amount m:type="Edm.Decimal">0</d:Line_Discount_Amount>
<d:Allow_Invoice_Disc m:type="Edm.Boolean">true</d:Allow_Invoice_Disc>
<d:Inv_Discount_Amount m:type="Edm.Decimal">0</d:Inv_Discount_Amount>
<d:Amount m:type="Edm.Decimal">0</d:Amount>
<d:Amount_Including_VAT m:type="Edm.Decimal">0</d:Amount_Including_VAT>
<d:Allow_Item_Charge_Assignment m:type="Edm.Boolean">true</d:Allow_Item_Charge_Assignment>
<d:Qty_to_Assign m:type="Edm.Decimal">0</d:Qty_to_Assign>
<d:Qty_Assigned m:type="Edm.Decimal">0</d:Qty_Assigned>
<d:Job_No />
<d:Job_Task_No />
<d:Job_Line_Type xml:space="preserve"></d:Job_Line_Type>
<d:Job_Unit_Price m:type="Edm.Decimal">0</d:Job_Unit_Price>
<d:Job_Line_Amount m:type="Edm.Decimal">0</d:Job_Line_Amount>
<d:Job_Line_Discount_Amount m:type="Edm.Decimal">0</d:Job_Line_Discount_Amount>
<d:Job_Line_Discount_Percent m:type="Edm.Decimal">0</d:Job_Line_Discount_Percent>
<d:Job_Total_Price m:type="Edm.Decimal">0</d:Job_Total_Price>
<d:Job_Unit_Price_LCY m:type="Edm.Decimal">0</d:Job_Unit_Price_LCY>
<d:Job_Total_Price_LCY m:type="Edm.Decimal">0</d:Job_Total_Price_LCY>
<d:Job_Line_Amount_LCY m:type="Edm.Decimal">0</d:Job_Line_Amount_LCY>
<d:Job_Line_Disc_Amount_LCY m:type="Edm.Decimal">0</d:Job_Line_Disc_Amount_LCY>
<d:Prod_Order_No />
<d:Blanket_Order_No />
<d:Blanket_Order_Line_No m:type="Edm.Int32">0</d:Blanket_Order_Line_No>
<d:Insurance_No />
<d:Budgeted_FA_No />
<d:FA_Posting_Type xml:space="preserve"></d:FA_Posting_Type>
<d:Depreciation_Book_Code />
<d:Depr_until_FA_Posting_Date m:type="Edm.Boolean">false</d:Depr_until_FA_Posting_Date>
<d:Depr_Acquisition_Cost m:type="Edm.Boolean">false</d:Depr_Acquisition_Cost>
<d:Duplicate_in_Depreciation_Book />
<d:Use_Duplication_List m:type="Edm.Boolean">false</d:Use_Duplication_List>
<d:Appl_to_Item_Entry m:type="Edm.Int32">0</d:Appl_to_Item_Entry>
<d:Shortcut_Dimension_1_Code />
<d:Shortcut_Dimension_2_Code />
<d:ShortcutDimCode_x005B_3_x005D_ />
<d:ShortcutDimCode_x005B_4_x005D_>70</d:ShortcutDimCode_x005B_4_x005D_>
<d:ShortcutDimCode_x005B_5_x005D_ />
<d:ShortcutDimCode_x005B_6_x005D_ />
<d:ShortcutDimCode_x005B_7_x005D_ />
<d:ShortcutDimCode_x005B_8_x005D_ />
</m:properties>
</content>
</entry>

Comments

  • vremeni4vremeni4 Member Posts: 323
    Hi,

    I think the error message is caused by the validation for one of the fields as you are trying to insert all fields at once.
    Create a codeunit in NAV, and create a function e.g.
    CreatePurchaseLine(DocumentType,DocumentNo,LineNo)
    In that function insert only fields which are part of the primary key
    PurchaseLine.Init;
      PurchaseLine."Document Type" := DocumentType;
      PurchaseLine."Document No." := DocumentNo;
      PurchaseLine."Line No" := LineNo;
    PurchaseLine.Insert;
    
    Publish this codeunit as a Web Service.
    Call this function first after that call you function but this time as MODIFY and not as insert.

    I hope this helps.

    Thanks.
  • NeetuNeetu Member Posts: 4
    Hi Patrick,

    Iam doing the same but unable to insert sales lines using Odata.

    Please help me. Can u please tell me the code how u inserted sales lines .
  • Jens_M-PJens_M-P Member, Microsoft Employee Posts: 39
    In order to use writable OData, you need to have controls on the page for all primary key fields. They do not have to be visible.
    I think that some key fields are missing from the purchase order subform - as the can be filled in using Autosplitkey in the client.
    Best regards,
    Jens Møller-Pedersen [MSFT]

    This posting is provided 'AS IS' with no warranties, and confers no rights.
  • NeetuNeetu Member Posts: 4
    Hi Jens,

    Can u please help me how to update sales lines.
    All the primary fields are available on the page .

    Please Help me .No error is thrown in Visual Studio but sales lines are not being updated.

    Regards,
    Neetu Rawat
  • Torben_Wind_Meyhoff[MSFT]Torben_Wind_Meyhoff[MSFT] Member, Microsoft Employee Posts: 22
    Go to page 55
    Add the two fields "Document No." and "Line No.".
    Mark both as Editable false and Visible false, so they will not appear in the clients.

    The page is now able to be inserted from OData.

    BR
    Torben
    “This posting is provided "AS IS" with no warranties, and confers no rights.”
  • Vinnie1991Vinnie1991 Member Posts: 3
    I recently started using the Nav ODATA Webservices. They work fine for the sales invoices. I can add a sales invoice and add lines to the sales invoice using the ODATA POST method.

    Just got a question about the first section:
    How did you do the OData POST method for the Sales Invoice?

    I'm trying to get the POST to OData (via JSON) working, but I still get a 400 error.
    Can you help me with some example code?
  • amr_wafaamr_wafa Member Posts: 23
    Hi All,

    Adding only one line is working fine, but cannot add multiple lines in one request. can anybody help?
  • pereiranuno88pereiranuno88 Member Posts: 6
    Hello,

    I me trying to create some Order Sales Line using page 42 publish as a WS.Can you help me with this error?

    {
    "odata.error": {
    "code": "",
    "message": {
    "lang": "en-US",
    "value": "Primary keyvalue(s) Document_Type are missing in insert command. Make sure that all primary keys on the page are backed by a control in order to be set."
    }
    }
    }


    Resquest


    POST /benNAVSTD/OData/Company('CRONUS%20Portugal%20SA')/SalesOrder(Document_Type='Order',No='1065')/SalesOrderSalesLines?$format=json HTTP/1.1
    Host: hostname:40330
    Content-Type: application/json


    {
    "Document_Type": "Order",
    "Document_No": "1065",
    "Line_No": 30000,
    "Type": "Item",
    "No": "1155"

    }
  • Wisa123Wisa123 Member Posts: 308
    Hi @pereiranuno88,
    "Document_Type": "Order",
    "Document_No": "1065",
    "Line_No": 30000,

    well those fields usually aren't shown in the "Sales Order Lines" Subpage - therefore the error.
    As described above, you need all key attributes to be included in the published page, according to your error this also applies to subpages.

    Solution 1) Add the fields to the subpage (invisible preferrably)
    Solution 2) Create a new Page (maybe a Copy) to do the API operations on.

    regards
    /Wisa
    Austrian NAV/BC Dev
Sign In or Register to comment.