Foros de discusión

Add user to organization, programmatically?

Mathias Hultman, modificado hace 11 años.

Add user to organization, programmatically?

New Member Mensajes: 3 Fecha de incorporación: 8/07/11 Mensajes recientes
I simply want to add a user to an organization (role Organization User), and tried with
UserLocalServiceUtil.addOrganizationUsers(org.getOrganizationId(), userIds);

However, it only works partially. When later questioning with;
OrganizationLocalServiceUtil.hasUserOrganization(model.getUserId(),org.getOrganizationId()));

..it returns true. But when looking at the organizations of the user, the membership does not show up. Also, when initially looking at all users and organizations (which displays non-members), the user shows up. Could you provide information of how to correctly give a user a membership of an organization? Time would be of the essence.


Thanks,
thumbnail
Prakash Khanchandani, modificado hace 11 años.

RE: Add user to organization, programmatically?

Expert Mensajes: 329 Fecha de incorporación: 10/02/11 Mensajes recientes
This might be a re-indexing issue, don't know for sure. Try re-indexing from the control panel after your code is executed.
Control panel --> Server Administration --> Re-index search criterias

But you can also check-out UserLocalServiceUtil#updateOrganizations() method and other methods to add/update organizations in UserLocalServiceUtil.
thumbnail
Mani kandan, modificado hace 11 años.

RE: Add user to organization, programmatically?

Expert Mensajes: 492 Fecha de incorporación: 15/09/10 Mensajes recientes
Try the below code,


Indexer indexer = IndexerRegistryUtil.getIndexer(Organization.class);
indexer.reindex(obejectlist);
Hetal Patel, modificado hace 11 años.

RE: Add user to organization, programmatically?

New Member Mensajes: 2 Fecha de incorporación: 14/08/12 Mensajes recientes
I think once you have added user to Organization, in order to update this user entry into DB, you should call this method.
OrganizationLocalServiceUtil.updateOrganization(organization, merge) , which will update Organization changes of memory into DB.
thumbnail
bhargavi m, modificado hace 9 años.

RE: Add user to organization, programmatically?

Junior Member Mensajes: 47 Fecha de incorporación: 5/04/12 Mensajes recientes
Have you got solution....

UserLocalServiceUtil.addOrganizationUsers(batchId, userId);

I have added user to organization but when am trying to delete it is not happening

UserLocalServiceUtil.unsetOrganizationUsers(batchId, userId);

It is giving fallowing exception
ERROR [Organization:175]
com.liferay.portal.NoSuchGroupException: No Group exists with the key {companyId=10154, classNameId=10003, classPK=601}
thumbnail
Pankaj Kathiriya, modificado hace 9 años.

RE: Add user to organization, programmatically?

Liferay Master Mensajes: 722 Fecha de incorporación: 5/08/10 Mensajes recientes
you can verify in database if you have any group exist with primary key as 601.
If not, then you are passing wrong batchId in your code.
thumbnail
bhargavi m, modificado hace 9 años.

RE: Add user to organization, programmatically?

Junior Member Mensajes: 47 Fecha de incorporación: 5/04/12 Mensajes recientes
am no where touching group here but y am getting that error
I have checked my db i dont have any group with that id
but that id wat i passed as batchId was orgId why the hell group got into this issue
thumbnail
bhargavi m, modificado hace 9 años.

RE: Add user to organization, programmatically?

Junior Member Mensajes: 47 Fecha de incorporación: 5/04/12 Mensajes recientes
some how the fallowing is working for me

UserLocalServiceUtil.addOrganizationUsers(orgID, userId);

Thanks for reply
thumbnail
Peter Svehla, modificado hace 9 años.

RE: Add user to organization, programmatically?

New Member Mensajes: 4 Fecha de incorporación: 19/03/12 Mensajes recientes
I think you'll find it useful to follow that with:
Indexer indexer = IndexerRegistryUtil.getIndexer(User.class);
indexer.reindex(user.getUserId());

I will allow you to find the membership if you go looking for it.