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.