Skip to content

Instantly share code, notes, and snippets.

@CorneAussems
Created October 11, 2017 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CorneAussems/f3f7613c3a64c8d1df1c3a57877478ea to your computer and use it in GitHub Desktop.
Save CorneAussems/f3f7613c3a64c8d1df1c3a57877478ea to your computer and use it in GitHub Desktop.
Liferay Remove and add UserGroup
import com.liferay.portal.service.*;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.util.*;
try{
serviceContext = new com.liferay.portal.service.ServiceContext()
long companyId = PortalUtil.getDefaultCompanyId()
employee = com.liferay.portal.service.UserGroupLocalServiceUtil.getUserGroup(companyId,"EMPLOYEE");
fired = com.liferay.portal.service.UserGroupLocalServiceUtil.getUserGroup(companyId,"FIRED_EMPLOYEE");
out.println(employee);
out.println(fired);
screenNames = "999,8888".split(",")
for( i=0; i<screenNames.length;i++){
screenName = screenNames[i];
user = UserLocalServiceUtil.getUserByScreenName(companyId,screenName)
out.println(user.getUserId());
try{
UserGroupLocalServiceUtil.deleteUserUserGroup(user.getUserId(),employee);
}catch(e){out.println('DELETE:'+e)}
try{
UserGroupLocalServiceUtil.addUserUserGroup(user.getUserId(),fired);
}catch(e){out.println('ADD:'+e)}
}
}catch(e){
out.println(e);
}
out.println('done');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment