on 2022 Dec 09 8:06 PM
Hello experts,
I am trying to consume ODATA v.4 service from MDK application, but I face some challenges to prepare the action call. According to the documentation “The OData library lets you interact with an OData endpoint to parse OData payloads, produce OData requests, and handle responses for OData versions 2 and 4.”
However I am not able to construct a post call to an entity action that is supposed to do an update of an entity. Here you are details for my example. I have attached metadata file (tour.xml).
The entity I would like to update is Users, and the call what I use to update it through a rest client (POSTMAN) looks like this (service endpoint path bolded):
https://ldcix38.devint.net.sap:44311 /sap/opu/odata4/sap/api_ilo_touroperations_o4/srvd_a2x/sap/touroperations/0001/Users('')/SAP__self.LogonToWarehouseResource
With payload:
{"EWMWarehouse" : "BS01","WarehouseResource" : "LEGO"}
And the service POST finishes successfully, updating the Logon status of the user.
I suppose that I am not able to create correct ReadLink, because my call fails with error:Resource not found for segment 'SAP__self.LogonToWarehouseResource'
My assumption is that to consume of an Action in ODATA v.4 I should use UpdateEntity, correct? Here you are the action, that I created and try to execute:
{
"_Type": "Action.Type.ODataService.UpdateEntity",
"ActionResult": {
"_Name": "EwmLogonActionResult"
},
"ShowActivityIndicator": true,
"OnSuccess": "/rtop/Actions/EwmLogon/EwmCheckRecovery.action",
"OnFailure": "/rtop/Rules/EwmLogon/EwmLogonFailure.js",
"Target": {
"Service": "/rtop/Services/tour.service",
"EntitySet": "Users",
"ReadLink": "{@odata.id}/SAP__self.LogonToWarehouseResource"
},
"Properties": {
"EWMWarehouse": "BS01",
"WarehouseResource": "DIMITROV"
}
}
May you tell me what I do wrong? The action I would like to call is named ‘LogonToWarehouseResource’ and seems well defined in the metadata file. For the ReadLink I tried different prefixes ({@odata.id}, {@odata.readLink}) with same failure.
I have attached tour.service file as well (with extension .txt to allow upload), where I explicitely had set dataVersion to 400 as per instructions in the documentation
Please advice. I will appretiate any hint that will help me to manage and execute a successful POST call from the application
Best Regards,
Dimiter
Request clarification before answering.
I don't have MDK experience but I know that the the underlying OData APIs wouldn't permit an action to be called via updateEntity.
Perhaps you need to use this option: https://help.sap.com/doc/3642933ef2e1478fb1578ef2acba4ae9/Latest/en-US/reference/schemadoc/Action/OD...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Evan,
Thank you for your comment and for the proposal. Unfortunately, I cannot use neither CallFunction to consume Entity action. The reason is that the actions exposed by our model are always assigned to an Entity, and the proposed API simply does not allow to code this, e.g. the CallFunctionTarget does not allow to point the entity
When I try to create ODATA action there is no warning or error by the validation but during the build I receive this error:
MDK Validator - Failed to get schema of action file:///Users/i824790/work/Projects/rtop/src/metadata/definitions/Actions/EwmLogon/LogonToWarehouseResource.action with the error: TypeError: Cannot read properties of undefined (reading 'alias')
MDK Validator - Failed to get schema of action file:///Users/i824790/work/Projects/rtop/src/metadata/definitions/Actions/EwmLogon/LogonToWarehouseResource.action with the error: TypeError: Cannot read properties of undefined (reading 'alias')
And runtime an exception is thrown:
com.sap.cloud.mobile.odata.core.UndefinedException: Undefined data method: LogonToWarehouseResource.
Regards,
Dimiter
Evan is correct. You use CallFunction to execute a Function Import or Action Import. I do not believe Functions and Actions are not executed in the context of an EntitySet per Odata but instead expect all the parameters to be passed into them and they act accordingly providing the return type in response.
Hello Bill,
I looked for an entity update, because Action I would like to use is tightly related to User: it is exposed as User Entity Action. It is not defined as ActionImport or FunctionImport – you can see this in the attached metadata file.
So, I would like to construct a URI in this way:
https://<service_endpoint>/Users('')/SAP__self.LogonToWarehouseResource
Following your advice I tried to use Action.Type.ODataService.CallFunction:
{
"_Type": "Action.Type.ODataService.CallFunction",
"ActionResult": {
"_Name": "EwmLogonActionResult"
},
"ShowActivityIndicator": true,
"OnSuccess": "/rtop/Actions/EwmLogon/EwmCheckRecovery.action",
"OnFailure": "/rtop/Rules/EwmLogon/EwmLogonFailure.js",
"Target": {
"Service": "/rtop/Services/tour.service",
"Function": {
"Name": "LogonToWarehouseResource",
"Parameters": {
"Resource": "/rtop/Rules/Resource/GetResource.js",
"Warehouse": "/rtop/Rules/Resource/GetWarehouse.js"
}
}
}
}
It seems to be accepted as a valid function name and build finishes without error.
But runtime I receive error and it is before the real call: the URL cannot be constructed at all, because LogonToWarehouseResource is not recognized. Screenshot with the error is attached:
I gave a try with ‘SAP__self.LogonToWarehouseResource’ as Function Name, as well as with ‘Users('')/SAP__self.LogonToWarehouseResource’ always with the same resultSo my question can be down casted to this one: how the segment concerning User would be added to the code in order to construct a call that is accepted by the backend
Thank you,
Dimiter
We will have to look into why the editor is not displaying the action names.
I don't believe we have call function support for actions bound to an entity set at this time. You may need to use REST Service Send Request action type in the meantime and you can open a feature request for enhancing the call function support longer term.
Hello bill.froelich jitendrakumar.kansal ,
I also checked with our backend developers and they said what evanireland stated in the previous comment: ADT cannot expose bound OData v.4 functions/actions in the entity container.
So my question can be rephrased : is there MDK API I can use to consume bound Action or Bound Function?
Thank you,
Dimiter
User | Count |
---|---|
77 | |
30 | |
10 | |
8 | |
8 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.