web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

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

(0) ShareShare
ReportReport
Posted on by 46

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?

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    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.

  • MikeWillis Profile Picture
    46 on at

    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.

  • DK-14060934-0 Profile Picture
    3 on at
    Thank you Mike Willi. You were correct that those fields have go in order to post sales lines. 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans