
Hey,
I'm trying to deep insert a PSA salesorder with salesorderdetails, orderlinetransactions etc. via WebAPI.
The request errors out because the PSA orderlinetransactions validation plugin is complaining that the lookup to the salesorderdetail is missing.
This is a test request body:
{
"shipto_freighttermscode": 1,
"msdyn_psastate": 192350000,
"name": "Kopie",
"paymenttermscode": 2,
"pricingerrorcode": 0,
"processid": "00000000-0000-0000-0000-000000000000",
"prioritycode": 1,
"totaltax": 0,
"billto_postalcode": "123",
"od4uc_versandartcode": 513110000,
"statecode": 0,
"od4uc_fuerbatchvorsehen": false,
"od4uc_steuerbetrag": 92.625,
"totallineitemamount": 487.5,
"msdyn_ordertype": 192350001,
"billto_city": "123",
"msdyn_ContractOrganizationalUnitId@odata.bind": "/msdyn_organizationalunits(a50d05e4-3df7-e811-a95c-000d3ab6dc82)",
"od4uc_nachbuchungvonlizenzencode": false,
"od4uc_stornoauftrag": false,
"od4uc_bereitsverteilterbetrag": 0,
"od4uc_gesamtbetragbrutto": 580.125,
"totalamount": 487.5,
"bms_email_setting": 0,
"totallineitemdiscountamount": 0,
"totaldiscountamount": 0,
"bms_anteil_cs_euro": 0,
"od4uc_rechnungsadresseueberkontakt": true,
"totalamountlessfreight": 487.5,
"customerid_account@odata.bind": "/accounts(c4ce13f1-46ed-ea11-a817-000d3a4ab96a)",
"msdyn_psastatusreason": 192350000,
"od4uc_namevertragseinheit": "bms-gruppe",
"skippricecalculation": 1,
"statuscode": 1,
"bms_abweichende_debitoreninformation": false,
"od4uc_steuersatzcode": 513110002,
"willcall": false,
"od4uc_gruppendatenklauselliegtvor": false,
"pricelevelid@odata.bind": "/pricelevels(9e052aa4-45ed-ea11-a817-000d3a4ab96a)",
"billto_line1": "123",
"billto_country": "Japan",
"order_details": [{
"od4uc_anteilesageuro": 0,
"productname": "Test",
"msdyn_linetype": 690970000,
"iscopied": true,
"od4uc_anteilbmstceuro": 0,
"msdyn_costamount": 0,
"od4uc_anteilnpoeuro": 0,
"extendedamount": 0,
"quantity": 1,
"bms_anteil_cs_euro": 0,
"od4uc_hilfsfeldanteilnpoeuroausdetailzeilen": 0,
"sequencenumber": 2,
"msdyn_includematerial": false,
"bms_anteil_digitaler_vertrieb_euro": 0,
"pricingerrorcode": 0,
"salesorderdetailname": "Test",
"msdyn_includefee": true,
"od4uc_ordertype": 192350001,
"msdyn_includetime": false,
"shipto_freighttermscode": 1,
"ispriceoverridden": true,
"od4uc_anteilnpoeuroausdetailzeilen": 0,
"od4uc_anteilbmsodeuro": 0,
"tax": 0,
"od4uc_anteilbmsmmmeuro": 0,
"skippricecalculation": 0,
"volumediscountamount": 0,
"msdyn_billingmethod": 192350001,
"msdyn_includeexpense": false,
"priceperunit": 0,
"productdescription": "Test",
"isproductoverridden": true,
"od4uc_anteilbmseuropublicerrechnet": 0,
"propertyconfigurationstatus": 2,
"od4uc_anteilbmsbankingeuro": 0,
"producttypecode": 5,
"willcall": false,
"description": "Changed the description",
"msdyn_salesorderdetail_msdyn_orderlinetransacti": [{
"msdyn_ResourceOrganizationalUnitId@odata.bind": "/msdyn_organizationalunits(a50d05e4-3df7-e811-a95c-000d3ab6dc82)",
"msdyn_accountingdate": "2020-09-10T22:00:00Z",
"msdyn_documentdate": "2020-09-10T22:00:00Z",
"msdyn_billingtype": 192350001,
"msdyn_enddatetime": "2020-09-10T22:00:51Z",
"msdyn_amountmethod": 192350000,
"statuscode": 1,
"msdyn_transactionclassification": 192350004,
"msdyn_quantity": 1,
"timezoneruleversionnumber": 0,
"msdyn_vendortype": 192350001,
"msdyn_price": 0,
"msdyn_PriceList@odata.bind": "/pricelevels(20b2759e-46ed-ea11-a817-000d3a4ab96a)",
"msdyn_transactiontypecode": 192350000,
"msdyn_AccountCustomer@odata.bind": "/accounts(c4ce13f1-46ed-ea11-a817-000d3a4ab96a)",
"msdyn_exchangeratedate": "2020-09-10T22:00:00Z",
"msdyn_startdatetime": "2020-09-10T22:00:51Z",
"msdyn_customertype": 192350001,
"msdyn_amount": 0
}, {
"msdyn_ResourceOrganizationalUnitId@odata.bind": "/msdyn_organizationalunits(a50d05e4-3df7-e811-a95c-000d3ab6dc82)",
"msdyn_accountingdate": "2020-09-10T22:00:00Z",
"msdyn_documentdate": "2020-09-10T22:00:00Z",
"msdyn_billingtype": 192350001,
"msdyn_enddatetime": "2020-09-10T22:00:51Z",
"msdyn_amountmethod": 192350000,
"statuscode": 1,
"msdyn_transactionclassification": 192350004,
"msdyn_quantity": 1,
"timezoneruleversionnumber": 0,
"msdyn_Origin@odata.bind": "/msdyn_orderlinetransactions(15af90c2-4af4-ea11-a815-000d3aafb97e)",
"msdyn_vendortype": 192350001,
"msdyn_price": 0,
"msdyn_PriceList@odata.bind": "/pricelevels(68fa3a09-47ed-ea11-a817-000d3a4ab96a)",
"msdyn_transactiontypecode": 192350004,
"msdyn_AccountCustomer@odata.bind": "/accounts(c4ce13f1-46ed-ea11-a817-000d3a4ab96a)",
"msdyn_exchangeratedate": "2020-09-10T22:00:00Z",
"msdyn_startdatetime": "2020-09-10T22:00:51Z",
"msdyn_customertype": 192350001,
"msdyn_amount": 0
}]
}, {
"od4uc_anteilesageuro": 0,
"productname": "T&M123123123",
"msdyn_linetype": 690970000,
"iscopied": true,
"od4uc_anteilbmstceuro": 0,
"msdyn_costamount": 0,
"od4uc_anteilnpoeuro": 0,
"extendedamount": 487.5,
"quantity": 1,
"bms_anteil_cs_euro": 0,
"od4uc_hilfsfeldanteilnpoeuroausdetailzeilen": 0,
"sequencenumber": 1,
"msdyn_includematerial": false,
"bms_anteil_digitaler_vertrieb_euro": 0,
"pricingerrorcode": 0,
"salesorderdetailname": "T&M123123123",
"msdyn_includefee": false,
"od4uc_ordertype": 192350001,
"msdyn_includetime": true,
"shipto_freighttermscode": 1,
"ispriceoverridden": true,
"od4uc_anteilnpoeuroausdetailzeilen": 0,
"od4uc_anteilbmsodeuro": 0,
"tax": 0,
"od4uc_anteilbmsmmmeuro": 0,
"skippricecalculation": 0,
"volumediscountamount": 0,
"msdyn_billingmethod": 192350000,
"msdyn_includeexpense": true,
"priceperunit": 487.5,
"productdescription": "T&M123123123",
"isproductoverridden": true,
"od4uc_anteilbmseuropublicerrechnet": 0,
"propertyconfigurationstatus": 2,
"od4uc_anteilbmsbankingeuro": 0,
"producttypecode": 5,
"willcall": false,
"description": "Changed the description",
"msdyn_salesorderdetail_msdyn_orderlinetransacti": [{
"msdyn_ResourceOrganizationalUnitId@odata.bind": "/msdyn_organizationalunits(a50d05e4-3df7-e811-a95c-000d3ab6dc82)",
"msdyn_accountingdate": "2020-09-13T22:00:00Z",
"msdyn_documentdate": "2020-09-13T22:00:00Z",
"msdyn_Unit@odata.bind": "/uoms(7886d424-3fed-ea11-a817-000d3aafb97e)",
"msdyn_billingtype": 192350001,
"msdyn_enddatetime": "2020-09-13T22:00:43Z",
"msdyn_amountmethod": 192350000,
"statuscode": 1,
"msdyn_transactionclassification": 192350000,
"msdyn_UnitSchedule@odata.bind": "/uomschedules(dad307c2-c3fc-e811-a95b-000d3ab6d5d9)",
"msdyn_quantity": 2,
"timezoneruleversionnumber": 0,
"msdyn_description": "Aufgabe 1",
"msdyn_vendortype": 192350001,
"msdyn_price": 81.25,
"msdyn_PriceList@odata.bind": "/pricelevels(20b2759e-46ed-ea11-a817-000d3a4ab96a)",
"msdyn_transactiontypecode": 192350000,
"msdyn_AccountCustomer@odata.bind": "/accounts(c4ce13f1-46ed-ea11-a817-000d3a4ab96a)",
"msdyn_exchangeratedate": "2020-09-13T22:00:00Z",
"msdyn_startdatetime": "2020-09-13T22:00:43Z",
"msdyn_customertype": 192350001,
"msdyn_amount": 162.5
}, {
"msdyn_ResourceOrganizationalUnitId@odata.bind": "/msdyn_organizationalunits(a50d05e4-3df7-e811-a95c-000d3ab6dc82)",
"msdyn_accountingdate": "2020-09-13T22:00:00Z",
"msdyn_documentdate": "2020-09-13T22:00:00Z",
"msdyn_Unit@odata.bind": "/uoms(7886d424-3fed-ea11-a817-000d3aafb97e)",
"msdyn_billingtype": 192350001,
"msdyn_enddatetime": "2020-09-13T22:00:43Z",
"msdyn_amountmethod": 192350000,
"statuscode": 1,
"msdyn_transactionclassification": 192350000,
"msdyn_UnitSchedule@odata.bind": "/uomschedules(dad307c2-c3fc-e811-a95b-000d3ab6d5d9)",
"msdyn_quantity": 2,
"timezoneruleversionnumber": 0,
"msdyn_description": "Aufgabe 1",
"msdyn_Origin@odata.bind": "/msdyn_orderlinetransactions(a6b2fff9-7ef6-ea11-a815-000d3a4ab96a)",
"msdyn_vendortype": 192350001,
"msdyn_price": 243.75,
"msdyn_PriceList@odata.bind": "/pricelevels(68fa3a09-47ed-ea11-a817-000d3a4ab96a)",
"msdyn_transactiontypecode": 192350004,
"msdyn_AccountCustomer@odata.bind": "/accounts(c4ce13f1-46ed-ea11-a817-000d3a4ab96a)",
"msdyn_exchangeratedate": "2020-09-13T22:00:00Z",
"msdyn_startdatetime": "2020-09-13T22:00:43Z",
"msdyn_customertype": 192350001,
"msdyn_amount": 487.5
}]
}]
}
Getting back a 400 error with the following message (translated to English):
XHRPOSTXXX.crm.dynamics.com/.../salesorders
[HTTP/1.1 400 Bad Request 3234ms
error Object { code: "0x80040265", message: "Value cannot be null.\r\nParameter name: The Salescontractline-ID is missing.", "@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionSourceKey": "Plugin/Microsoft.Crm.ObjectModel.CustomBusinessEntityService", … }
code "0x80040265"
message "Value cannot be null.\r\nParameter name: The Salescontractline-ID is missing."
@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionSourceKey "Plugin/Microsoft.Crm.ObjectModel.CustomBusinessEntityService"
@Microsoft.PowerApps.CDS.ErrorDetails.ApiStepKey "4fcabb1b-ea3e-db11-86a7-000a3a5473e8"
@Microsoft.PowerApps.CDS.ErrorDetails.ApiDepthKey "1"
@Microsoft.PowerApps.CDS.ErrorDetails.ApiActivityIdKey "4b0fea6d-6852-4f26-9019-58854fd2fdaa"
@Microsoft.PowerApps.CDS.ErrorDetails.ApiPluginSolutionNameKey "System"
@Microsoft.PowerApps.CDS.ErrorDetails.ApiStepSolutionNameKey "System"
@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionCategory "ClientError"
@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionMesageName "IsvAborted"
@Microsoft.PowerApps.CDS.ErrorDetails.ApiExceptionHttpStatusCode "400"
@Microsoft.PowerApps.CDS.ErrorDetails.OperationStatus "0"
@Microsoft.PowerApps.CDS.ErrorDetails.SubErrorCode "-2146233088"
@Microsoft.PowerApps.CDS.TraceText "\r\n[Microsoft.Dynamics.ProjectService.Plugins: Microsoft.Dynamics.ProjectService.Plugins.PreValidateContractLineDetailCreateInputValidation\r\n[6b688e0a-43c7-4cf4-b7ba-d52836740195: Project Service - PreValidateContractLineDetailCreateInputValidation\r\n\r\n"
@Microsoft.PowerApps.CDS.InnerError.Message "Value cannot be null.\r\nParameter name: Die Projektvertragszeilen-ID fehlt."
It's the msdyn_salescontractlineid lookup that is causing the error.
This lookup should be automatically populated with the GUID of the newly created salesorderdetail up the chain. I cannot know it at the time of creation of the request body.
If I disable the plugin message Microsoft.Dynamics.ProjectService.Plugins.PreValidateContractLineDetailCreateInputValidation, it works as expected.
What gives?