on 07-06-2022 6:48 PM
Hi CAP experts david.kunz2 gregorwolf iobert mioyasutake thomas.jung
Below is my schema and service
test_Service.cds-> Entities: Entity1(Draft-Enabled), Entity2(Draft-Enabled), Upload( Singleton entity with one field for excel data and no persistence in DB).
In test-service.js, I implemented an Upload handler srv.on("PUT", Upload), where I read excel data and insert it into Entity1 or Entity2( I passed entity name dynamically from separate UI modules/apps developed for both entities). For inserting I use INSERT.into(entity).entries(data).
Problem Statement: I want to carry out some validations on data before inserting into the respective entities. Is there a way I can invoke srv.before or srv.on event handlers of Entity1 or Entity2 on calling the statement INSERT.into(entity).entries(data) which is written inside handler of Upload srv.on("PUT", Upload)?
Thanks
Kanika
Hello Kanika,
we achieved this functionality by running the query object not on the db or cds but on the service in question:
const query = UPDATE.entity('<entity-name>').byKey(<identifier>).set({
status: 100
});
let srv = await cds.connect.to('<srv-name>');
return await srv.run(query);
On a side note: in our setting only queries using the String name of the entity triggered the correct event, using the reflected entity instead of the string did not work!
Best,
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Martin
This was great, worked like a charm.
Thanks a lot.
Also I would like to highlight this point because that does the trick. It only works when passed the entity name as String(without any namespace)
On a side note: in our setting only queries using the String name of the entity triggered the correct event, using the reflected entity instead of the string did not work!
Regards
Kanika
User | Count |
---|---|
74 | |
10 | |
8 | |
7 | |
6 | |
5 | |
5 | |
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.