Fórum

can any one tell me... how to Add user to organization, programmatically

piyush shukla, modificado 8 Anos atrás.

can any one tell me... how to Add user to organization, programmatically

Junior Member Postagens: 46 Data de Entrada: 18/09/15 Postagens Recentes
Add user to organization, programmatically? can you provide information about this
thumbnail
Harish Kumar, modificado 8 Anos atrás.

RE: can any one tell me... how to Add user to organization, programmaticall

Expert Postagens: 483 Data de Entrada: 31/07/10 Postagens Recentes
piyush shukla:
Add user to organization, programmatically? can you provide information about this




/**
	* @throws SystemException if a system exception occurred
	*/
	public static void addOrganizationUser(long organizationId, long userId)
		throws com.liferay.portal.kernel.exception.SystemException {
		getService().addOrganizationUser(organizationId, userId);
	}
piyush shukla, modificado 8 Anos atrás.

RE: can any one tell me... how to Add user to organization, programmaticall

Junior Member Postagens: 46 Data de Entrada: 18/09/15 Postagens Recentes
Hi Harish Kumar


but i just want to know- how to call this method addOrganizationUser
like this addOrganizationUser(organizationId,userIds); we will pass organizationId like this or is there any way for passing organizationId
i'm not sure about this calling method
thumbnail
Harish Kumar, modificado 8 Anos atrás.

RE: can any one tell me... how to Add user to organization, programmaticall

Expert Postagens: 483 Data de Entrada: 31/07/10 Postagens Recentes
UserLocalServiceUtil.addOrganizationUser(organizationId,userId)

pass the organization id and user id ;
Piyush Shukla, modificado 8 Anos atrás.

RE: can any one tell me... how to Add user to organization, programmaticall

Junior Member Postagens: 46 Data de Entrada: 18/09/15 Postagens Recentes
Hi Harish

// i'm calling like this method regularOrg and OrgUser method inside updateInstance
Organization org = null;
org = CreateRegularOrg(companyName, company.getCompanyId());

addOrganizationUser(org, tenantAdminName,tenantAdminEmailId);


//this method for create regularOrganization(this is woking fine for me (regular organization is creating))
SuppressWarnings({ "unused", "deprecation" })
private Organization CreateRegularOrg(String tenant, long companyId) {

ServiceContext serviceContext = ServiceContextThreadLocal
.getServiceContext();
serviceContext.setCompanyId(companyId);
Organization org = null;
try {
org = OrganizationServiceUtil.addOrganization(0, tenant,"regular-organization", true, 19014, 19, 12017,StringPool.BLANK, true, serviceContext);
org.setCompanyId(companyId);

org = OrganizationLocalServiceUtil.updateOrganization(org);
org.getExpandoBridge().setAttribute("tenant ", tenant);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
return org;
}


Now i want to create user inside above regular organization(this code is not working for me user is not creating inside organization)

private void addOrganizationUser(Organization org, String tenantAdminName,String tenantAdminEmailId)
throws PortalException {

ServiceContext serviceContext = ServiceContextThreadLocal
.getServiceContext();
User user = null;

try {
Company company = CompanyLocalServiceUtil.getCompany(org.getCompanyId());

User newUser = UserLocalServiceUtil.createUser(CounterLocalServiceUtil.increment());
newUser.setFirstName(tenantAdminName);
newUser.setEmailAddress(tenantAdminEmailId);
newUser.setCompanyId(org.getCompanyId());
newUser.setScreenName(tenantAdminEmailId);

UserLocalServiceUtil.addOrganizationUser(org.getOrganizationId(),newUser);
UserLocalServiceUtil.addUser(newUser);

} catch (SystemException e) {
e.printStackTrace();
}


}
THANKS IN ADVANCE
please tell mehwre i'm doingmistake actually i'm new in liferay creating user and organizatin by programatically please help me out