cancel
Showing results for 
Search instead for 
Did you mean: 

Personas 3.0 SP 4 - Get user name in JavaScript.

former_member238607
Participant
0 Kudos
704

Hi,

I'm creating a flavor for IW21, and I need to load the user's name into a Reported By field using JavaScript.

I've searched for an answer in numerous posts, and I keep seeing a reference to SY-UNAME. However, this appears to be a system variable available for ABAP, but not JavaScript.

I would also like to be able to use the user name for a remote function call to BAPI_USER_GET_DETAIL, but the examples I've found, like the one below, use a hard-coded user name and don't explain how to get that dynamically.

var rfc = session.createRFC("BAPI_USER_GET_DETAIL");
rfc.setParameter("USERNAME", "PRIYADARSHIS");
rfc.requestResults(JSON.stringify(["ADDRESS", "RETURN"]));
rfc.send();

Can someone provide a JavaScript example on how I can get the user name?

Thank you very much for your help!

View Entire Topic
tamas_hoznek
Product and Topic Expert
Product and Topic Expert

session.info.user will give you the current user name.

babowden
Explorer
0 Kudos

Hello,

How can i add this as a Java script to automatically apply the username to the `Reported By` field, when the screen is loaded?

Many Thanks,

Ben

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

babowden: You could use session.info.user in an onLoad script to populate the field you want.

If this is a backend field, then

session.findById("wnd[0]/usr/ctxtSOMETHING-REPORTEDBY").text = session.info.user;
Or for a custom field you added in your flavor:
session.findById("wnd[0]/usr/txtPersonas_17024162180208").text = session.info.user;