Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Resolving errors when ...
Finance forum
Answered

Resolving errors when creating new sales orders

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
  • Layan Jwei Profile Picture
    Layan Jwei 6,884 Super User 2024 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
  • ddrudge Profile Picture
    ddrudge 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
    Layan Jwei 6,884 Super User 2024 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
    ddrudge 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:
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 6,884 Super User 2024 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
    ddrudge 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.
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 6,884 Super User 2024 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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,137 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans