Symptom
Business Add-Ins (BAdIs) for sales documents does not work when creating the sales order via API. But the BAdI works well when creating the sales order manually via the "Create Sales Orders - VA01" or "Manage Sales Orders" app.
Environment
SAP S/4HANA Cloud Public Edition
Cause
One of the reasons for this kind of issue is that, the logic implemented in the BAdI is executed only when a certain CDS View (taking the view I_Customer as an example here) is accessed. However, the communication user used to create the sales order via API is not provided with the authorization to access this CDS View.
For example, the beginning of the BAdI may look like this:
SELECT SINGLE TradingPartner FROM I_Customer
WHERE Customer = @salesdocument - soldtoparty
INTO @lv_vbund.
……
Resolution
Please assign a communication scenario which has the authorization to select from I_Customer, to the communication user and the communication system. For example: https://api.sap.com/api/API_BUSINESS_PARTNER/overview
Please be noticed that, the access to the view I_Customer is by default not provided either for the API user or the user creating sales orders manually via the "Create Sales Orders - VA01" / "Manage Sales Orders" app. The reason why the user can create sales orders manually with the BAdI working well, lies in that it is provided with the needed authorization from another channel (the security team on the customer side should know how to achieve this).
Keywords
Business Add-Ins, BAdIs, Sales Documents, API, CDS View, Create Sales Orders - VA01, Manage Sales Orders, Authorization, Communication User, Communication System, Communication Scenario, Communication Arrangement , KBA , SD-SLS-API , API , SD-SLS-API-2CL , API (Public Cloud) , Problem