cancel
Showing results for 
Search instead for 
Did you mean: 

Preview in Fiori Elements over a CAP service with @odata.draft.enabled

Cassaro
Explorer
0 Kudos

Hello!

I´m facing a problem while trying to build a List Report front end on top of a CAP service which I enabled for CRUD operations. I´m assuming that @odata.draft.enabled enables the entity for CRUD, so my service is like this (simplest service I can figure out):

schema.cds:

namespace p4;
entity Ent1 {
 key id: Integer;
 description: String(100);
}

cat-service.cds:

using { p4 as my } from '../db/schema';
@path:'/catalog'
service CatalogService {
@odata.draft.enabled
 entity Ent1 as projection on my.Ent1;
} 

As I run it locally and launch the "preview in Fiori" I have all the buttons for CRUD. I can update and delete entries. But as I try to create an entry that´s what happens:



This is the data from the 'Headers' section:

Request URL: 
http://localhost:4004/catalog/$batch
Referrer Policy: 
no-referrer-when-downgrade
Request HeadersAccept: 
multipart/mixed
Accept-Encoding: 
gzip, deflate, br
Accept-Language: 
pt-BR
Connection: 
keep-alive
Content-Length: 
330
Content-Type: 
multipart/mixed; boundary=batch_id-1594208238132-51
Host: 
localhost:4004
MIME-Version: 
1.0
OData-MaxVersion: 
4.0
OData-Version: 
4.0
Origin: 
http://localhost:4004
Referer: 
http://localhost:4004/$fiori-preview/?service=CatalogService&entity=Ent1
Sec-Fetch-Dest: 
empty
Sec-Fetch-Mode: 
cors
Sec-Fetch-Site: 
same-origin
User-Agent: 
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
X-CSRF-Token: 
null
X-Requested-With: 
XMLHttpRequest
Request Payload--batch_id-1594208238132-51
Content-Type:application/http
Content-Transfer-Encoding:binaryPOST Ent1 HTTP/1.1
Accept:application/json;odata.metadata=minimal;IEEE754Compatible=true
Accept-Language:pt-BR
X-CSRF-Token:
Content-Type:application/json;charset=UTF-8;IEEE754Compatible=true

{}
--batch_id-1594208238132-51--

This $batch request is kind of confusing to me, but it looks like the List Report is sending the POST with no data inside the curly-brackets and this is being rejected by the CAP service. It looks odd to me. On the console we got this:

POST /catalog/$batch
> NEW Ent1 null
[2020-07-08T11:37:18.170Z | ERROR | 1788582]: Cannot convert undefined or null to object
[2020-07-08T11:37:18.170Z | ERROR | 1788582]: Error stacktrace: TypeError: Cannot convert undefined or null to object
at removeDraftUUID (C:\Dev\Estudo\Cds\ws1\p4\node_modules\@sap\cds-runtime\lib\cds-services\services\utils\draftUtils.js:224:5)     at C:\Dev\Estudo\Cds\ws1\p4\node_modules\@sap\cds-runtime\lib\cds-services\services\handlers\onCreateDraft.js:96:14
[INTERNAL ERROR] TypeError: Cannot convert undefined or null to object
    at removeDraftUUID (C:\Dev\Estudo\Cds\ws1\p4\node_modules\@sap\cds-runtime\lib\cds-services\services\utils\draftUtils.js:224:5)
    at C:\Dev\Estudo\Cds\ws1\p4\node_modules\@sap\cds-runtime\lib\cds-services\services\handlers\onCreateDraft.js:96:14
Please report this error.

I have also tried to deploy (similar service, the real one) to CF and use Fiori-Tools to have a "real" app running over the V2 (server.js approach) , but for this one I get a different error in the same point:

502 Bad Gateway: Registered endpoint failed to handle the request.

I figured out that in this case the failing request is like this:

###
POST http://localhost:8080/v2/adm/Ingredientes
Content-Type: application/json
{"__metadata":{"type":"AdmService.Ingredientes"}}

and the response is like this:

HTTP/1.1 502 Bad Gateway
x-powered-by: Express
content-type: text/plain; charset=utf-8
x-cf-routererror: endpoint_failure
x-content-type-options: nosniff
date: Wed, 08 Jul 2020 12:01:38 GMT
Content-Length: 67
connection: close
strict-transport-security: max-age=31536000; includeSubDomains; preload;
Vary: Accept-Encoding

502 Bad Gateway: Registered endpoint failed to handle the request.

This is kind of similar with this other question:

https://answers.sap.com/questions/13063525/how-to-handle-crud-operation-in-fiori-elements-cap.html?c...

But in my case I´m not getting the SAML2 message, and I´m don´t have the SAML2 parameter in my manifest.json (generated by the fiori tools).

I have also tried to generate the List Report with the WebIDE wizard. This one generates the SAML2 paramters but I removed it and the results are the same.

Well, I have been writen a lot here... To sumarize it, all I want to do is to put up together a functional List Report CRUD over a simple CAP service. I´m trying it with that @odata.draft.enabled annotation but with no success, be it local preview (odata v4) or app on cloud (odata v2). If someone could please put some light on it to me I would thank you very much!

Thanks! Eric

chgeo
Advisor
Advisor
0 Kudos

Thanks for the detailed report. I am not sure at the moment if this is a client-side Fiori issue or something in the server. However, I do know that Fiori preview uses an older SAP UI5 version (1.73.1), which might have issues. With the CAP July release, it will be using the latest version again. In the meanwhile, you can try launching the UI from an own html (see the sample) to check if latest UI5 behaves better.

Cassaro
Explorer
0 Kudos

Thanks Christian for the reply! Not lucky yet here. I generated my own front-end via Fiori-Tools and it backend rejects it´s create(empty POST) request with the response '502 Bad Gateway: Registered endpoint failed tohandle the request.'. I also tried to make my own index.html like in the sample you gave me but I get different bugs with it when launching the app from the tile. Maybe things doesn´t fit well with this setup I made up from the sample. But let´s put this aside for now and wait for the new release. Thanks again. I´m having lots of fun with CAP in general \m/

Accepted Solutions (1)

Accepted Solutions (1)

former_member643578
Participant
0 Kudos

I had same issue but you can do this by changing key id : UUID; then you can do create operation.

Cassaro
Explorer
0 Kudos

Many thanks! You made my day!

Answers (0)