cancel
Showing results for 
Search instead for 
Did you mean: 

Passing currently logged in user id into an input field

Former Member
0 Kudos

Hello Gurus,

I have an application where i need to pass the currently logged in user ID into an input field, on that ID his employee smartform will be displayed via RFC. please send me the code to do so.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dear Shilpi,

1. Add component tc/je/usermanagement/api as a 'Used DC' (NW 7.0) / 'Required DC' (NW7.11 and up)

2. Use the below code to get the logged in User

try

{

      IWDClientUser CurrentUser = WDClientUser.getCurrentUser();

      String UserId = WDClientUser.getCurrentUser().getSAPUser().getUniqueName();

}

catch(Exception e)

{

     e.printStackTrace();

}

Thanks & Regards,

Patralekha

Former Member
0 Kudos

Hi,

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi All,

My problem got solved as i have rearranged my code and paste it in initialization to show the smart form on click of the tab according to the currently logged in user.

thank you everyone for helping me out.

thanks alot

Former Member
0 Kudos

Hi,

I created two applications on the same RFC, in one of the applications the employee id is manually inputted and there is no error for the same. But when the currently logged in user id is fetched automatically, it is showing error.

govardan_raj
Contributor
0 Kudos

hi shipi,

In the second case , where you told that on fetching the currently logged user id ... u r getting error , it shows while creating applicaiton you have not checked the authentication check box.

No worries for this component you have created application right ,

double click the applicaiton, it opens application properties at the right hand side.

now in the right hand side you have properties and application properites , choose Application properties tab.

Click New Button->

Now click Browse ->Choose Authentication -->In value drop down Choose True --now click finish

now build your dc and deploy the same.

like since you have  not applied authentication to your application so wdclient.getuser...etc will give null

now if you enable authentication to your application then it fetches the user.

Regards

Govardan Raj S

Former Member
0 Kudos

Hi Gurus,

I use this code and my application is working very fine. When I am deploying  the application, form is coming according to currently logged in user but it is also showing error

  Fill in all required entry fields , error key: RFC_ERROR_SYSTEM_FAILURE

The code for user from display is:

try

  {

  WDClientUser.getCurrentUser().getSAPUser().getUniqueName();

  user = WDClientUser.getCurrentUser().getSAPUser().getUniqueName();

  //wdContext.currentZfm_Empform_Portal_InputElement().setUsrid(CurrentUser());

  }

  catch(Exception e)

  {

  e.printStackTrace();

  }

  //String UserId1 = UserId;

  try

  {                       

  //wdContext.currentZfm_Empform_Portal_InputElement().setUsrid(wdContext.currentZfm_Empform_Portal_InputElement().getUsrid());

  wdContext.currentZfm_Empform_Portal_InputElement().setUsrid(user);

  wdContext.currentZfm_Empform_Portal_InputElement().modelObject().execute();

   }

  catch (WDDynamicRFCExecuteException e)

   {

    e.printStackTrace();

    wdContext.currentContextElement().setPdf_data(e.getMessage());

    }

   

  wdContext.currentContextElement().setPdf_data(convertXStringToURL(wdContext.currentOutputElement().getBin_File()));  

please help me to resolve this issue.

govardan_raj
Contributor
0 Kudos

Dear shilpi,

In your RFC , some input attributes will be manadatory , check with your abaper , it is getting passed empty i mean no value is being passed to the rfc for that mandatory attribute .

so only you are getting rfc_error_system_failure..

Ask your abaper to give the test Data for executing the rfc, hard code those values and check the execution..

in the exception block as suggested earlier

StringWriter StrWriter = new StringWriter();

   Mylog.Myloc.errorT(StrWriter.toString());

   PrintWriter PntWWriter = new PrintWriter(StrWriter);

   StrWriter.getBuffer().setLength(0);

   exception.printStackTrace(PntWWriter);

   Mylog.Myloc.errorT(wdComponentAPI.getApplication().getName()+StrWriter.toString());

and create myLoc class  in the

//@beging others

public static class Mylog

  {

     private static final Location Myloc = Location.getLocation("com.yourorg.MyLogController");

  }

//@end others

you will get in detailed info in the nwa logs and traces..

Hi can u please post your error complete giving much more details.....?

Regards

Govardan

Former Member
0 Kudos

Hi Govardan,

Thanks for your instant reply, I checked my ABAPER, the userid is optional in the RFC. and the screenshot for the same is:

Here, I am supposed to click on Display button, the form will be displayed for the currently logged in user; where I am getting error:

govardan_raj
Contributor
0 Kudos

hi ,

on click of display button ,

what is the code being executed , there as suggested can u put in try catch block and post the logs that are coming in nwa , or else you can put this in exception block.

//-------------------------------------------

catch (Exception e) 

{

  StackTraceElement element[] = e.getStackTrace();

  StringBuffer buffer = new StringBuffer();

  for(int i=0;i<element.length;i++)

  {

   buffer.append(element[i]);

  }

  wdComponentAPI.getMessageManager().reportException(buffer.toString(),true);

}

//-----------------------------------------

it will show the exactl line number where dump occurs we can trace the error easily...

Regards

Govardan Raj

Former Member
0 Kudos

thank u gurus for ur instant help.

former_member191044
Active Contributor
0 Kudos

Hi Shilpi.

WDClientUser.getCurrentUserOrNull().getSAPUser().getUniqueName()

this will return the current user logon id.

Regards Tobias.