Skip to main content



No record found.

Microsoft Dynamics NAV forum
Suggested answer

Cannot use oData to insert Sales Line for Document Type = 'Order'

Posted on by 44

I have a PHP script that inserts Quotes for us. The basic procedure is:

  1. insert Sales Header, get Header Number back (such as '12345')
  2. insert Sales Lines, using Header Number '12345' as the Document No. Other fields are:
    • Line No.
    • Type
    • No.
    • Quantity
    • Document Type
    • Unit Price
    • Line Discount Percent
    • Description

This has been active for years and works fine. Today I started a new script that needs to insert Sales Lines onto Orders instead of Quotes. The final insert is literally exactly the same as the Quote insert (using all of the same code), except two fields are different:

  1. Document No. will be something like 'SO56789'
  2. Document Type will be 'Order'

Unfortunately this fails every time, with this error:

"The field Document No. of table Sales Line contains a value (SO56789) that cannot be found in the related table (Sales Header)."

Looking at the tables in Nav, the Sales Line table has column 'Document No.' with value 'SO56789' and the Sales Header table has column 'No.' with value 'SO56789'. I can't figure out why it fails. It's worth emphasizing that this works fine as a quote - all code is exactly the same, column names are the same, etc.

Is there some other field I have to pass to insert a line on an Order document?

  • DK-14060934-0 Profile Picture
    DK-14060934-0 3 on at
    Cannot use oData to insert Sales Line for Document Type = 'Order'
    Thank you Mike Willi. You were correct that those fields have go in order to post sales lines. 
  • MikeWillis Profile Picture
    MikeWillis 44 on at
    RE: Cannot use oData to insert Sales Line for Document Type = 'Order'

    I'm not sure if this is what you were getting at Suresh but I checked the Keys for each table in question (Sales Header and Sales Line), then I compared them to the Web Services Pages I had created (WS_SalesHeader and WS_SalesLine). They were not in the same order.

    For example the Keys for Sales Header table were 'Document Type,No.' and Keys for Sales Line were 'Document  Type,Document No.,Line No.'.

    Meanwhile my WS_SalesLine had the columns in this order: 'Document No., Line No., <other columns>, Document Type'. My WS_SalesHeader had the columns in this order: 'Document Type, <other columns>, No.'.

    So I changed my Services so the keys were defined first, and in the same order as the actual table definitions. That solved the problem - Sales Lines are now inserted correctly for both Quotes and Orders.

    I'm not sure why these Web Services worked fine for Quotes but failed for Orders, but at least it's working now.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,638 on at
    RE: Cannot use oData to insert Sales Line for Document Type = 'Order'

    how are the web services published? If they have published a sales quote or something which has the filter for document type then you cannot create an order using the same service.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans