cancel
Showing results for 
Search instead for 
Did you mean: 

created by coming as "anonymous" in SAP CAP even after deployment

Ahmedkhan29789
Participant
0 Kudos

Hello SAP CAP Experts,

I have created a simply cds table with managed and I want to get the created by and modified by fields, As SAP has given this inbuilt functionality using "manage", when i post the records into my table via an entity the createdby and modifiedby fields fills with value "anonymous".

My schma.cds file have this code

using { Currency, managed, cuid, sap} from '@sap/cds/common';
entity Promo: managed, cuid {

key ID : Integer; STATUS : String;

PROMOTION_TYPE : String;

key key WEEK : Date

}

In my service.cds i have it like this
entity Promotions as projection on PromService.Promotions;

What else I need to do to get the correct user in createdby and modifiedby fields?

0 Kudos

Hi Ahmed,

the managed-aspect handler automatically fills the user column with the logon name of the business request user. Requests w/o authentication have "anonymous" as user name to indicate the public access. So if you configure authentication, you'll see the corresponding user names.

Br

Matthias

Ahmedkhan29789
Participant
0 Kudos

Hi matthia.braun,

In my package.json, I have added these highlighted codes, even though it's not working, when I am sending the records via odata using my deployed Fiori application

Accepted Solutions (0)

Answers (2)

Answers (2)

gregorw
Active Contributor

To get real users stored in the created by field you have you add Authentication.

Ahmedkhan29789
Participant
0 Kudos

Hi Gregor,
I Checked this that I have added authentication as mentioned in the link you have shared, in my package.json, even though it's not working, when I am sending the records via odata using my deployed Fiori application

MioYasutake
Active Contributor
0 Kudos

You need below annotation either on service level or entity level to have your user authenticated.

@requires: 'authenticated-user'

example:

service CustomerService @(requires: 'authenticated-user'){
  ...
}
service CustomerService {
  entity Orders @(restrict: [ 
    { grant: ['READ','WRITE'], to: 'authenticated-user' },
]){/*...*/} }
Ahmedkhan29789
Participant
0 Kudos

Now i tried this, Locally the app is working but on deployment to cloud foundry its failing...

I thought managed service was provided by SAP to save developers time :D, I will try with some node js code to solve this or may be fetch user in frontend and fill it in a manual createdby field.