cancel
Showing results for 
Search instead for 
Did you mean: 

get UserName from UserID. how ?

former_member187977
Participant
0 Kudos

HI,

Is there a API in portal or dynpro using which I can get UserID from the UserName. for example: username enterted by a user on the web dynpro screen is "XYZ". Now, he clicks on a button 'get ID'. User "XYZ" is maintained in portal. How to fetch UserID programatically ?

Regards

seventyros

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

You can make use of IUserFactory and IUserSearchFilter APIs to search for users maintained in portal (UME), by providing either firstname, or lastname or userId or all the three. You will get the set of users whose details matches your search criteria.

Below is an example,


try {
IUserFactory userFactory = UMFactory.getUserFactory();
IUserSearchFilter searchFilter = userFactory.getUserSearchFilter();
searchFilter.setFirstName("firstName", ISearchAttribute.LIKE_OPERATOR, false);
searchFilter.setLastName("LastName", ISearchAttribute.LIKE_OPERATOR, false);
searchFilter.setUniqueName("userId",ISearchAttribute.LIKE_OPERATOR, false);
ISearchResult searchResult = userFactory.searchUsers(searchFilter);
while (searchResult.hasNext()) {
        IUser user = UMFactory.getUserFactory().getUser(searchResult.next().toString());
        user.getFirstName();
        user.getLastName();
        user.getUniqueName();
}
} 
catch (Exception e) {
	wdComponentAPI.getMessageManager().reportException(e.getMessage());
}

So you can set either firstname or lastname and user.getUniqueName() will get you UserId.

Regards,

Vishweshwara P.K.M.

0 Kudos

We are using the same code to read user id and name.

junwu
Active Contributor
0 Kudos

hi buddy, your title and content are totally different,

which you want? get id from name or name from id?

id from name: you have to make search

name from id:

IUser user = userFactory.getUserByLogonID(userId);
			user.getFirstName()

Qualiture
Active Contributor
0 Kudos

You could retrieve the corresponding IUser object with all corresponding getters using

IWDClientUser wdUser = WDClientUser.getClientUser("youruserid");
IUser user = wdUser.getSAPUser();

Cheers,

Robin