cancel
Showing results for 
Search instead for 
Did you mean: 

Error cds build in action: A type, an element, or a service entity is expected here

fjcv
Explorer

Hi,

Since the Cds compile update to version @sap/cds-compiler: 2.1.4, cds build/all is not working propertly.

using { serv as my } from '../db/Test';


service api  @(requires:'authenticated-user'){
    entity Test as projection on my.Test;  
    action insertMultipleTest(value : array of my.Test) returns response;
}

define type response {
    response : String(12)
}

[ERROR] srv\test-services.cds:6:37-46: A type, an element, or a service entity is expected here (in action:“api.insertMultipleTest”/param:“value”)

I follow the instruction:

https://cap.cloud.sap/docs/cds/compiler-v2

Fix: Rewrite such references from Foo.a to Foo:a.

to replace with:

action insertMultipleTest(value : array of my:Test) returns response;

And I got the same error for node services and java services.

Thank you and kind regards

Accepted Solutions (0)

Answers (3)

Answers (3)

079695
Explorer

Looks like the problem here is that the referred entity in the action's param is declared outside of the service. If you use the projection Test, which is part of the service, the error should be resolved, like so:

action insertMultipleTest(value : array of Test) returns response;
hjb
Advisor
Advisor
0 Kudos

Hi, all types referred to in an action/function definition MUST be member of the same defining service.

service action {
  entity Test as projection on api.Test;
  action insertMultipleTest(value : array of Test) returns response;
  type response { response : String(12) }
}
fjcv
Explorer
0 Kudos

Hi,

Before the cds-compiler upgrade to version 2.1.4 the code works perfectly because I referred to entity from my db/Test with my.Test and in https://cap.cloud.sap/docs/cds/compiler-v2 they said that you can fix your references with: Fix: Rewrite such references from Foo.a to Foo:a.

So, Now I should modify my code because I can not reference with my.Test or my:Test.?

using { serv as my } from '../db/Test';


service api  @(requires:'authenticated-user'){
    entity Test as projection on my.Test;  
}
serives act{
action insertMultipleTest(value : array of my.Test) returns response;
}
define type response {
    response : String(12)
}
079695
Explorer
0 Kudos

As per the guide, there are 2 recommendations of how to mitigate this in compiler version 2.

Fix Option 1 Add a projection on the entity in the service and use this as foo’s return type. This I already showcased in my previous answer - just use the projection from the current service of the desired entity. If there is the need to use an entity from another service the mechanism is the same, just use as a source the entity from the other service:

service api {
    entity Test as projection on my.Test;  
}
service action {
    entity Test as projection on api.Test;
    action insertMultipleTest(value : array of Test) returns response;
}

Fix Option 2 Define and use an auxiliary type, for example type T : E {}. If you would like to implement this fix option, it will be something like so:

service action {
    type Test : my.Test {};
    action insertMultipleTest(value : array of Test) returns response;
}
fjcv
Explorer
0 Kudos

Hi,

It is possible to choose the version of sap/cds-compiler because I would like to compile with a previous version 1.4.XX for example. How I can do it?

Best

0 Kudos

Hi,

that would be possible (by having a CDS 4 version) as dependency, but the resulting EDMX would be incorrect.

If you are not interesting in a EDMX, you could something like the following use to compile (but not to OData!)

service api {
    entity Test as projection on my.Test;  
}
service action {
    action insertMultipleTest(value : array of api.Test) returns String;
}
fjcv
Explorer
0 Kudos

Hi Elena,

Thank you very much for reply but is works when the action is in the same service in case that action is in different services is not works, I got:

No artifact has been found with name "Test" (in action:"action.insertMultipleTest"/param:"value") and I can not compile.

service api {
    entity Test as projection on my.Test;  
}
service action {
    action insertMultipleTest(value : array of Test) returns response;
}

Best