Skip to main content

Notifications

Small and medium business | Business Central, N...
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,745 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.

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