legacy-knowledge-base
公開されました Jun. 30, 2025

Organization tab do not shows the user when user is added to organization via Groovy Script

written-by

Rishabh Agrawal

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

Issue

  • After the execution of the below syntax in the Groovy Script, the Organization name gets appended to the user and can be seen only under the "User's details Organization Tab" but not under the "Organizations tab".
    import com.liferay.portal.kernel.service.*;
    out.println (OrganizationLocalServiceUtil.addUserOrganization(userId, organizationId));

Steps to reproduce:

1. Login to Liferay DXP 2024.Q1.12.
2. Create any user with any details from the Users & Orgs screen.
3. Create an organization with any name in the organization tab.
4. Run the below Groovy script to get organizationId and replace "OrganizationName" with the name with which the organization is created. CompanyId can be found from the Virtual Instance option in the Control Panel.

import com.liferay.portal.kernel.service.*;
out.println (OrganizationLocalServiceUtil.fetchOrganization(companyId, "OrganizationName"));

5. Now run the below Groovy script in order to attach the user to the respective organization.        Replace the userId parameter which can be found in the User's details screen and get the organizationId by executing the above script.

import com.liferay.portal.kernel.service.*;
out.println (OrganizationLocalServiceUtil.addUserOrganization(userId, organizationId));

6. After the 5th step is performed, it is observed that in the User's details Org Tab, the user is mapped with the respective organization but when visiting the Organization tab, it shows "No Users Found".

Actual Result: After executing the Groovy script in step 5, the organization name gets appended to the user and can be seen only under the "User's details Organization Tab" but not under the "Organizations tab".
Expected Result: After executing the Groovy script in step 5, the organization tab should show the associated users.

Here is the attached video showcasing the behavior of the issue.

Environment

  • Liferay DXP [all versions]

Resolution

  • Follow any of the below solutions in order to resolve the issue:

Solution 1:

1. Login to Liferay DXP 2024.Q1.12.
2. Create any user with any details from the Users & Orgs screen.
3. Create an organization with any name in the organization tab.
4. Run the below Groovy script to get organizationId and replace OrganizationName with the name with which the organization is created. "CompanyId" can be found from the Virtual Instance option in the Control Panel.

import com.liferay.portal.kernel.service.*;
out.println (OrganizationLocalServiceUtil.fetchOrganization(companyId, "OrganizationName"));

5. Run the below Groovy script in order to attach the user to the respective organization. Replace the userId parameter which can be found in the User's details screen and get the organizationId by executing the above script.

import com.liferay.portal.kernel.service.*;
out.println (OrganizationLocalServiceUtil.addUserOrganization(userId, organizationId));

6. Execute the below Groovy script to be able to view the user in the organization tab. This groovy script is used to launch the user indexing. Please note to add the userId parameter.

import com.liferay.portal.kernel.model.*;
import com.liferay.portal.kernel.search.*;
import com.liferay.portal.kernel.service.*;

Indexer<User> indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
indexer.reindex(UserLocalServiceUtil.fetchUser(userId)); 

Solution 2:

  • The service "OrganizationLocalServiceUtil.addUserOrganization(userId, organizationId)" is used within other services that perform indexing.
  • However, to avoid unnecessary indexing, it was decided not to launch an indexing in that service. The service that adds a user to the organization and automatically performs indexing is "UserLocalServiceUtil.addOrganizationUser(organizationId,userId)".
  • Therefore, in order to get the user added to an organization, replace the new script with the previous script [Step 5] as mentioned below:

Previous script:

import com.liferay.portal.kernel.service.*;
out.println (OrganizationLocalServiceUtil.addUserOrganization(userId, organizationId));

Replace with:

import com.liferay.portal.kernel.service.*;
out.println (UserLocalServiceUtil.addOrganizationUser(organizationId,userId));
did-this-article-resolve-your-issue

legacy-knowledge-base