cancel
Showing results for 
Search instead for 
Did you mean: 

CAP Extensibility: Exended Properties displayed in UI but missing in Requests

jreimann
Participant
0 Kudos

Hi guys,

currently we are evaluating the CAP framework's extensibility feature.

We already extended our base entity with a new property and pushed the changes via `cds push` to the tenant. A new column is created on the tenant's database in the corresponding table and and a new entry is added to the "CDS_XT_Extensions" table. We implemented a simple Fiori Elements app to test the CRUD operations. Reading the extended entity with the new property works fine, but writing doesn't.

Our base entity:

entity Person : cuid {
    FirstName                    : String(256);
    LastName                     : String(256);
    Age                          : Integer;
}

Annotation for the extension:

using {
  mymodel.Person,
  MyService.Persons
} from 'myservicedefinition';

extend mymodel.Person with { 
  City : String(256);
}
...

The POST request's payload:

{"__metadata {"type":"MyService.Persons"},"FirstName":"John","LastName":"Doe","City":"Chicago","Age":23}

We are running CAP in an express server with a custom server.js and OData V2 Adapter Proxy.

app.use(
    cov2ap({
        port: 3001,
        path: "v2",
        services: {
            "/odata": "MyService",
        },
    })
);

await cds
    .serve("MyService", { crashOnError: false })
    .at("/odata")
    .in(app)
    .with((srv: any) => {
        srv.on("READ", "Persons", async (req, next) => {
            const persons = await next();
			// Result: [{"FirstName":"Bill","LastName":"Grays","Age":22,"City":"London","ID":"2970e507-c8ba-46c7-b669-d5851d2db669"}]
            return persons;
        });
        srv.on("CREATE", "Persons", async (req) => {
            console.log(JSON.stringify(req.data));
            // {"FirstName":"John","LastName":"Doe","Age":34,"City":"Chicago","ID":"ba5c4cd6-9630-497d-948e-4e4d7a7e8f0d"}
        });
    });
    });

// Serve services for handling subscriptions & extensions.
cds.serve([
    "@sap/cds-mtxs/srv/cf/saas-provisioning-service",
    "@sap/cds-mtxs/srv/deployment-service",
    "@sap/cds-mtxs/srv/model-provider",
    "@sap/cds-mtxs/srv/jobs-service",
    "@sap/cds-mtxs/srv/extensibility-service",
])
    .in(app);

The data for the extended property "City" successfully reaches our OnCreate handler as you can see in the in the code snippet above, but the column on the tenant's database stays empty. We assume that the framework somehow "looses" the data of the new field on the way to the database.

Further findings:
- The findings apply to OData v2 and v4
- Calling the $metadata endpoint for the tenant, we can see the extended property "City"
- Reading an entry of Persons (like /Persons(guid'2970e507-c8ba-46c7-b669-d5851d2db669')) the new property "City" is missing
- Reading an entry of Persons with explicitly passing columns (like /Persons(guid'2970e507-c8ba-46c7-b669-d5851d2db669')?$select=ID,FirstName,LastName,Age,City)) the new property "City" is included in the result

Is it possible that there is a connection between the missing property in the result of the READ without specified columns and the non-persisted data for the extended property in the CREATE/UPDATE? Has anyone ever had the same problem and been able to solve it or does anyone have an idea what we are missing?

Kind regards,
Johannes

 

 

 

Accepted Solutions (0)

Answers (0)