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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Resolving errors when creating new sales orders

(0) ShareShare
ReportReport
Posted on by 11
I am new to using Finance & Operations and the api for it. I have a been able to explore the odata API following the instructions for Postman.  For a client, I need to automatically create sales orders and line items from within our nodejs application.
So far it looks like:
 
const salesOrder = {  InvoiceCustomerAccountNumber: 'W253437',  OrderingCustomerAccountNumber: 'W253437',  RequestedShippingDate: '2023-08-01T10:10:10Z'};
const response = await client.fetch('/data/SalesOrderHeadersV2', {  method: 'POST',  body: JSON.stringify(salesOrder)});
 
The client class just adds the Authorization header and the host to the request.
 
The response shows the following issues:
Write failed for table row of type 'SalesOrderHeaderV2Entity'. Infolog: Warning: The value 'DAT-000020' in field 'Sales order' is not found in the related table 'Sales order purchase order link'.; Warning: validateField failed on field 'SalesOrderHeaderV2Entity.SalesOrderNumber'; Warning: The value 'W253437' in field 'Customer account' is not found in the related table 'Customers'.; Warning: validateField failed on field 'SalesOrderHeaderV2Entity.OrderingCustomerAccountNumber'; Warning: The value 'W253437' in field 'Invoice account' is not found in the related table 'Customers'.; Warning: validateField failed on field 'SalesOrderHeaderV2Entity.InvoiceCustomerAccountNumber'.
 
I'm not sure about any of these issues:
It seems like the SalesOrderNumber field is being autogenerated fine, why is it looking in a 'Sales order purchase order link' table as if it is a foreign key?
The query /data/Customers?$filter=CustomerAccount eq 'W253437' returns a customer for me, so why can it not be found when I make a post?
 
Some additional context, our client created a sandbox for me to test in to prove the integration prior to using their production system.  I'm not sure exactly what he did, but it kind of looks like he created a snapshot from their production system and put it in the sandbox. Is it possible that some indexes are not properly set up, causing this issue?
 
thanks in advance
I have the same question (0)
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Resolving errors when creating new sales orders
    Hi Community User,
     
    I can see you are facing errors related to customer account. In which dataAreaId does this customer account W253437 exist?
    By default, odata returns data from the user dataArea defined in setup. If this customer account exists in a different dataArea, then you'll need to use the cross-company keyword and specify the correct dataArea in the url.
    http://[baseURI\]/data/EntityName?$filter=dataAreaId eq 'usmf'&cross-company=true
     
    If you still face errors after this, then please share them and we'll look at them
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • ddrudge Profile Picture
    11 on at
    Resolving errors when creating new sales orders
    I've used &cross-company=true in the Customers entity query (it was showing up without it too) and in the POST to SalesOrderHeadersV2 and the results are still the same.
     
    Using my personal credentials in the UI, I can successfully create a sales order.  Using the API key with odata fails.
  • Verified answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Resolving errors when creating new sales orders
    Hi ddrudge,

    can share with us what you did exactly?

    Here's an example that i just tried and it works perfectly fine.

    Here's the body of the request


    and here's the header of the request:



    Now how did you get the token?
    1. you need to define the clientId in your FO environment
    2. You need to call the authorization api to get the token (by specifying the clientId, clientsecret, grantType and resource) in the body. Ans specifying the tenantId in the URL
    The resource will be your environment URL

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • ddrudge Profile Picture
    11 on at
    Resolving errors when creating new sales orders
    Some progress!  I did not know about the dataAreaId being required.  That seems to have cleared up the customer account issue, so that's great!
     
    I'm still having an issue where the SalesOrderNumber gets auto-generated, but is not valid somehow.
    My client id and client secret are valid - I get an access token and I can find the customer using it for Authorization:
    The error I get now:
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Resolving errors when creating new sales orders
    Hi ddrudge,

    What is this table "Sales order purchase order link"? is it standard? and are there any customizations on the sales order? as I didn't get such error



    Thanks,
    Layan Jweihan
     
  • ddrudge Profile Picture
    11 on at
    Resolving errors when creating new sales orders
    It turned out that our client had some custom validation and logic that was added to the ui forms that was not added generically. They are refactoring it so that it all applies the same regardless of whether it comes from a ui form or from odata.
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Resolving errors when creating new sales orders
    Hi ddrudge,
     
    Yes i suspected that there are customizations. I'm glad you found the issue. Please verify the answers that helped you like the dataAreaId to help others in the future.
     
    Thanks,
    Layan Jweihan

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans