problem in getting phone numbers for a user

4556825, modified 15 Years ago. Junior Member Posts: 55 Join Date: 2/2/10 Recent Posts
Hi All,

I want to get Phones for a specific user.

I tried PhoneUtil.findByUserId(userId) but getting Hibernate exception.

How can i use this method.


Thanks
Lalit
thumbnail
174078, modified 15 Years ago. Liferay Master Posts: 758 Join Date: 9/27/07 Recent Posts
lalit mohan:
Hi All,

I want to get Phones for a specific user.

I tried PhoneUtil.findByUserId(userId) but getting Hibernate exception.

How can i use this method.


Thanks
Lalit


The PhoneUtil is supposed to be invoked from a *LocalServiceImpl.

Try using the below.

PhoneServiceUtil.getPhones(Contact.class.getName(), userId);


Edit: In the above classPK will be contactId and not userId.
thumbnail
1545856, modified 15 Years ago. Liferay Legend Posts: 1744 Join Date: 11/6/08 Recent Posts
Hi,

Use this snippet

//companyId  = you can get it as user.getCompanyId()
//className = replace that with User.class.getName()
//classPK = userId
List<phone> phones = PhoneLocalServiceUtil.getPhones(companyId, className, classPK)</phone>


Regards,
Sandeep
4556825, modified 15 Years ago. Junior Member Posts: 55 Join Date: 2/2/10 Recent Posts
Hi Sandeep & Shagul

When i am using this

PhoneServiceUtil.getPhones(Contact.class.getName(), new Long(request.getRemoteUser()))

Getting Excpetion
com.liferay.portal.NoSuchUserException: No User exists with the key {contactId=16101}
at com.liferay.portal.service.persistence.UserPersistenceImpl.findByContactId(UserPersistenceImpl.java:1096)



Then i tried this.

PhoneServiceUtil.getPhones(Phone.class.getName(), new Long(request.getRemoteUser()))

Getting Exception
com.liferay.portal.security.auth.PrincipalException
at com.liferay.portal.service.permission.CommonPermissionImpl.check(CommonPermissionImpl.java:79)



Then i tried this
PhoneLocalServiceUtil.getPhones(company.getCompanyId(), User.class.getName(), new Long(request.getRemoteUser()))

Getting empty list.


None of these are working.
Why we are passing User class name for getting Phone objects?



Thanks
Lalit
thumbnail
174078, modified 15 Years ago. Liferay Master Posts: 758 Join Date: 9/27/07 Recent Posts
When you pass contact as the className, pass the contactId for classPK.

PhoneLocalService is used for contacts, organizations etc. In your case you are trying to get the phone number for the contact. You could refer the portal source on how the phone numbers are displayed for a user.
4556825, modified 15 Years ago. Junior Member Posts: 55 Join Date: 2/2/10 Recent Posts
Thanks

that is working
PhoneServiceUtil.getPhones(Contact.class.getName(), user.getConatctId());