Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

OData: Create mutliple new ECO products

Posted on by 6
Hello Dynamics 365 Community,
I am working with D365 FO for the last few months and although there is hardly resources on the topic I was able to get to know the system and how I can do stuff. Overall I was told to learn more about how to use OData requests to create, update and read entities. With the metadata that worked quite well after some time. 
 
My Problem:
I need to create multiple products in an ECO header using OData. These products should appear with ChangeType "New" and Impact "New product". Using the UI that is possible without any problem. You can just click on "New" and select "Create new product". After that a window appears (that looks like the one for creating an engineering product), you fill in the data and the entry will be created for you.
With OData requests I am creating products "differently". I am not able to create two products with ChangeType "New" and impact "New product". The error says something like: New product already exists in ... 

Am I missing something, how did you solve that? Is there a hint you can give me?


I would love to hear from you! Thank you very much in advance!
Sincerely
Christian

PS: I have written a super long message explaining everything in details but I was not able to create the post in this way. Hardly any documentation on OData and no working forum ... Love it ... 
Categories:
  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    OData: Create mutliple new ECO products
    I'm not familiar with this data entity, therefore I can't straight away what's wrong. I think the best approach will be debugging the entity to see what's going on there.
     
    EngChgEngineeringChangeOrderProductV3EntitysetFieldsForNewProduct() may be a good starting point.
  • CH-11120820-0 Profile Picture
    CH-11120820-0 6 on at
    OData: Create mutliple new ECO products
    I am working on a feature where we use OData Requests to create entities in Dynamics 365 FO. Among other things, we use the Engineering Change Management module to manage products. In a use case, we create an EngineeringChangeOrder (ECO) header and then add various ECO products. This involves not only existing ECO products, but also new ECO products to be created.
     
    Let's assume I have already created the ECO header. Then I can add ECO products in the UI by pressing this button and then selecting whether I want to create a product or add an existing one.
     
    A window opens and I can create a new product. (Note: It looks to me as if I am creating an EngineeringProduct here)
     
    An entry with the corresponding data is created. The ChangeType has the status ‘New’ and the Impact has the status ‘New product’. In the line itself, you can see the item number ‘300’ that I have selected. The product details are not visible here. This contains the ‘NewItemNumber’, which also corresponds to 300. I can repeat this process as often as I like via the UI. (Of course with different item numbers and product names).
     
    But that only applies to the UI. If I want to perform the same case with OData requests, it behaves differently.
    The first request works perfectly:
     
    POST https://{{d365_url}}/data/EngineeringChangeOrderProductsV3
    {
        "dataAreaId": "demf",
        "EngineeringChangeOrderNumber": "TestEco",
        "LineNumber": 2.0,
        "EngineeringProductCategoryDetailsName": "Test",
        "EngineeringChangeImpactType": "NewProduct",
        "ProductName": "CreatedUsingOData",
        "ProductSearchName": "EcoProduct",
        "NewProductVersionId": "V-01",
        "NewItemNumber": "301",
        "BOMUnitSymbol": "pcs"
    }
    
    The result in the UI looks like this: (Note: The item number is actually missing from this entry. However, the statuses have been set correctly. Also not visible. In the product details, the ‘NewItemNumber’ is correctly set to 301.
     
     
    I was puzzled by the item number. I also tried to add the item number here as CurrentItemNumber. If I used a number that does not exist, I got an error message that the item to be added could not be found. I concluded from this that I can use ‘NewItemNumber’ and ‘CurrentItemNumber’ to control whether I want to add a new or existing ECO product.
    When I want to add another new product to the ECO header I get a 400 HTTP error code.
     
    POST https://{{d365_url}}/data/EngineeringChangeOrderProductsV3
    {
        "dataAreaId": "demf",
        "EngineeringChangeOrderNumber": "TestEco",
        "LineNumber": 3.0,
        "EngineeringProductCategoryDetailsName": "Test",
        "EngineeringChangeImpactType": "NewProduct",
        "ProductName": "CreatedUsingOData2",
        "ProductSearchName": "EcoProduct",
        "NewProductVersionId": "V-01",
        "NewItemNumber": "302",
        "BOMUnitSymbol": "pcs"
    }
    
    {
        "error": {
            "code": "",
            "message": "An error has occurred.",
            "innererror": {
                "message": "Write failed for table row of type 'EngChgEngineeringChangeOrderProductV3Entity'. Infolog: Warning: New product  exists in the engineering change order TestEco and cannot be added.; Warning: The new product number  is already reserved in engineering change order TestEco; Warning: validateWrite failed on data source 'EngChgEcmProduct (EngChgEcmProduct)'.",
                "type": "Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataWriteException",
                "stacktrace": "   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateProcessor.CreateEntity_Save(ChangeOperationContext context, ChangeInfo changeInfo)\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.ExecuteActionsInCompanyContext(IEnumerable`1 actionList, ChangeOperationContext operationContext)\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.TrySave(ChangeOperationContext operationContext)\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateManager.SaveChanges()\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataDelegatingHandler.<SaveChangesAsync>d__2.MoveNext()"
            }
        }
    }
    What I have also tried is creating an EngineeringProduct with the corresponding OData request and then adding this product as an ‘Existing Product’. The problem here is that the ChangeType is set directly to ‘Changed’ (I can't change this with OData either). 
    In the end, it seems to me that a separate ‘Create new product’ request is missing for this UseCase. Or I'm missing something in the settings.
    In the end I have to apologise. I just shared bad information. I was unprofessional because I was a bit pissed off. That I couldn't post my first written entry directly in this forum.
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    OData: Create mutliple new ECO products
    Aha, you mean Engineering Change Orders, and - if I understand it correctly - you're trying to create several lines under the same header (i.e. with the same EngineeringChangeOrderNumber).
     
    The error appears if you're trying to add an exactly the same item again (ItemId and InventDimId are the same, plus there are a few more conditions). Is it your intention? All you said was "I need to create multiple products", which doesn't sound like you want to the same item multiple times.
  • CH-11120820-0 Profile Picture
    CH-11120820-0 6 on at
    OData: Create mutliple new ECO products
    Sorry I messed something up. The last error message was created when I tried to add "CurrentItemNumber" to my request. I will send the initial error message now:
     
    {
        "error": {
            "code": "",
            "message": "An error has occurred.",
            "innererror": {
                "message": "Write failed for table row of type 'EngChgEngineeringChangeOrderProductV3Entity'. Infolog: Warning: New product  exists in the engineering change order TestEco and cannot be added.; Warning: The new product number  is already reserved in engineering change order TestEco; Warning: validateWrite failed on data source 'EngChgEcmProduct (EngChgEcmProduct)'.",
                "type": "Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataWriteException",
                "stacktrace": "   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateProcessor.CreateEntity_Save(ChangeOperationContext context, ChangeInfo changeInfo)\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.ExecuteActionsInCompanyContext(IEnumerable`1 actionList, ChangeOperationContext operationContext)\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.TrySave(ChangeOperationContext operationContext)\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateManager.SaveChanges()\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataDelegatingHandler.<SaveChangesAsync>d__2.MoveNext()"
            }
        }
    }
     
  • CH-11120820-0 Profile Picture
    CH-11120820-0 6 on at
    OData: Create mutliple new ECO products
    As I mentioned in the post. For whatever reason I was not able to share all details with you initially. I will try to rn.
     
    {
        "error": {
            "code": "",
            "message": "An error has occurred.",
            "innererror": {
                "message": "Write failed for table row of type 'EngChgEngineeringChangeOrderProductV3Entity'. Infolog: Error: The released product 230 does not exist.",
                "type": "Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataWriteException",
                "stacktrace": "   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateProcessor.CreateEntity_Save(ChangeOperationContext context, ChangeInfo changeInfo)\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.ExecuteActionsInCompanyContext(IEnumerable`1 actionList, ChangeOperationContext operationContext)\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.ChangeInfo.TrySave(ChangeOperationContext operationContext)\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateManager.SaveChanges()\r\n   at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataDelegatingHandler.<SaveChangesAsync>d__2.MoveNext()"
            }
        }
    }
    This is the whole error message. I already understood that a number for the product is reserved. However I need to copy the functionality of the UI. (Adding multiple new ones is allowed there). Using the request I simply cant do it. 
    This is probably due to Dynamics managing something differently in the background. But I have no clue and the documentation on that is ... yeah. 
  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    OData: Create mutliple new ECO products
    What is the full error message? Aren't you violating any unique index?
     
    What do you mean by ECO header? ChangeType field doesn't exist in EcoResProduct table; you must mean something else (or it's a customization).

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans