Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
problem in getting phone numbers for a user
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
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
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.
Hi,
Use this snippet
Regards,
Sandeep
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
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
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
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.
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.
Thanks
that is working
PhoneServiceUtil.getPhones(Contact.class.getName(), user.getConatctId());
that is working
PhoneServiceUtil.getPhones(Contact.class.getName(), user.getConatctId());