cancel
Showing results for 
Search instead for 
Did you mean: 

Search for Portal User in Web Dynpro application

natalia_kogan
Explorer
0 Kudos

Hi all,

I have a problem with function "UserSearch" in my WebDynpro application. With following code I cannon have data user who registered with the portal.

try {

IUserFactory ufact = UMFactory.getUserFactory();

IUserSearchFilter isf = ufact.getUserSearchFilter();

// data from input field

String mySearchStr = wdContext.currentContextElement).getUserDataSelect();

//Provide the search attributes

isf.setDisplayName("" + mySearchStr + "",ISearchAttribute.LIKE_OPERATOR,false);

//Start search

ISearchResult sr = ufact.searchUsers(isf);

String strtest = sr.toString().toUpperCase();

IUser user = UMFactory.getUserFactory().getUser(strtest);

//put <b>user.getUniqueName</b>() -> in context Node

} catch (UMException e) {

e.printStackTrace();

}

Can some one give me pointers or some sample code of web dynpro which we can search specific user in the portal (Search parameters: ID, Last/First Name)

Thanks,

Natalia

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi natalia

use the portal user management api by importing the portal ume api jar files

to check for the portal user.then you can use the portal api to search the user.

regards

saravana

natalia_kogan
Explorer
0 Kudos

hi saravana,

thank for your help. In help portal and sdn I found enough information about UME but not realy good info for searching for user. For example I tempted this solution but without success.

http://help.sap.com/saphelp_nw04/helpdata/en/0f/807300c5754ed79107dcd9c2ae4ef4/frameset.htm

Do you have any more information or coding about searching user?

best regards,

Natalia

Former Member
0 Kudos

Hi,

Whats the problem you are facing..

You are not getting any data ? can u elobarate on this..

Regards

Bharathwaj

Former Member
0 Kudos

Hi,

Assuming u get more than one user.. in the search result.. and u r converting it to string.. it will give worng results right..!!

1.Try printing the search result..

2. Try getting a user object by directly giving the username..

3.Restrict the search so that it will give u only one result..

Try all these options.. and use this..

ISearchResult sr = ufact.searchUsers(isf);

String str = sr.next(); and not toString()...

It should work...:)

Regards

Bharathwaj

Message was edited by: Bharathwaj R

Message was edited by: Bharathwaj R

natalia_kogan
Explorer
0 Kudos

Hello Bharathwaj,

I had to try your recomendation but without result. It is not works. Although I search user by directly giving the username (user display name as search paremeter) and printing the serch result in the table.

try {

IUserFactory iuf = UMFactory.getUserFactory();

IUserSearchFilter usf = iuf.getUserSearchFilter();

// Input field for search parameter

String search = wdContext.currentContextElement().getUserDataSelect();

//Provide the search attributes

usf.setDisplayName(

search,

ISearchAttribute.EQUALS_OPERATOR,

false);

//Start search

ISearchResult sr = iuf.searchUsers(usf);

while(sr.hasNext())

{

IUser user = UMFactory.getUserFactory().getUser(sr.next().toString());

// put to the table in context

wdContext.currentUserSearchElement().setUserId(user.getUniqueName());

wdContext.currentUserSearchElement().setUserName(user.getDisplayName());

}

} catch (UMException e) {

e.printStackTrace();

}

If you have more ideas please give me your feedback.

Thanks,

Natalia

Former Member
0 Kudos

Hi Natalie,

This is supposed to work..:(

There might be some exception.. e.printStackTrace() wont print the output in the console..

use message manager and use the Exception class.. and not a specific child like UMException.

We might have a chance here..

usf.setDisplayName(
search,
ISearchAttribute.EQUALS_OPERATOR,
false);

//Start search
ISearchResult sr = iuf.searchUsers(usf);
while(sr.hasNext())
{
IUser user = UMFactory.getUserFactory().getUser(sr.next().toString());
// put to the table in context
wdContext.currentUserSearchElement().setUserId(user.getUniqueName());
wdContext.currentUserSearchElement().setUserName(user.getDisplayName());

}

} catch (Exception e) {
wdComponentAPI.getMessageManager().reportException(e.toString((),true);
}

Regards

Bharathwaj

natalia_kogan
Explorer
0 Kudos

Hello Bharathwaj,

thinks for you help. The user search function works right now , but by puting to the context table I have null.exception point error message. I will try to solve this problem.

Do you know casually what is the season ?

thanks and best regards,

Natalia

Former Member
0 Kudos

Hi,

winter !

Are u trying to put it in a node..


wdContext.currentUserSearchElement().setUserId(user.getUniqueName());

Have u created this user search element in the node..?

When u try to access an element without creating any , you will get null pointer exception

That must be the reason.. (My best guess!)

Regards

Bharathwaj

natalia_kogan
Explorer
0 Kudos

Hi Bharathwaj,

thank you very much. It's works!!!

best regards,

Natalia

Answers (2)

Answers (2)

arun_srinivasan
Contributor
0 Kudos

hi,

Try using the following codes

IUserFactory iuf = UMFactory.getUserFactory();

IUserSearchFilter usf = iuf.getUserSearchFilter();

String search = wdContext.currentSearchElement().getSearchKey();

search = "" + search + "";

usf.setSearchMethod(usf.SEARCHMETHOD_OR);

you need to include com.sap.security.api.jar file to implement.

Also see this thread for more information

/thread/35152 [original link is broken]

hope it helps...

regards,

Arun

natalia_kogan
Explorer
0 Kudos

Hello Arun,

Sorry , I am new to web dynpro and for me is not clearly how can I access to selected user date if I use the methode usf.setSearchMethod(usf.SEARCHMETHOD_OR);

Can you sent me more details?

What about search input parameters:is it possible to search for lastname, firstname or user id ?

P:S: I have included com.sap.security.api.jar file in my project.

Thanks for your help

Natalia

Former Member
0 Kudos

Hi Natalia,

Check on to this thread u will find the solution of solving ur problem,

Hope tihs helps u,

Regards,

Nagarajan.