Liferay 7.2 - How to add groups programmatically?Liferay 7.2 - How to add groups programmatically?https://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1148479122024-03-29T05:46:43Z2024-03-29T05:46:43ZRE: Liferay 7.2 - How to add groups programmatically?Fabio Carvalhohttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1148482582019-08-23T11:32:21Z2019-08-23T11:32:21Z<html><head></head><body>Hi Christoph,<br><br>After some debugging I found what could be the correct way to create a group programmatically. My method is the following:<br><pre><code>public void addGroup(ActionRequest request, ActionResponse response) throws IOException, PortletException, PortalException {
&nbsp; &nbsp; ThemeDisplay theme = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);&nbsp; &nbsp; long userId = theme.getUserId();
&nbsp; &nbsp; String name = ParamUtil.getString(request, "name");
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; Map<locale, string> nameMap = new HashMap<locale, string>();
&nbsp; &nbsp; nameMap.put(LocaleUtil.US, name);
&nbsp; &nbsp; nameMap.put(LocaleUtil.PORTUGAL, name);
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; GroupLocalServiceUtil.addGroup(
&nbsp; &nbsp; &nbsp; &nbsp; userId,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; GroupConstants.DEFAULT_PARENT_GROUP_ID,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; null,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; 0,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; GroupConstants.DEFAULT_LIVE_GROUP_ID,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; nameMap,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; null,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; GroupConstants.TYPE_SITE_OPEN,
&nbsp; &nbsp; &nbsp; &nbsp; false,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; null,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; true,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; true,&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; new ServiceContext()
&nbsp; &nbsp; );
}</locale,></locale,></code></pre><br>I think this is creating a site/organization if I am not mistaken.</body></html>Fabio Carvalho2019-08-23T11:32:21ZRE: Liferay 7.2 - How to add groups programmatically?Christoph Rabelhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1148500092019-08-23T11:29:51Z2019-08-23T11:29:51ZWhat kind of groups?<br />The term group is a bit ambiguous in Liferay. Do you want to add Usergroups or do you want to add sites/organisations?Christoph Rabel2019-08-23T11:29:51ZLiferay 7.2 - How to add groups programmatically?Fabio Carvalhohttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1148479112019-08-23T10:33:27Z2019-08-23T10:33:27Z<html><head></head><body>Hi,<br><br>I am trying to add groups and layouts programmatically in my custom portlet. Right now I am successfully adding layouts like this:<br><pre><code>public void addLayout(ActionRequest request, ActionResponse response) throws IOException, PortletException, PortalException {
&nbsp; &nbsp; ThemeDisplay theme = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; long userId = theme.getUserId();
&nbsp; &nbsp; long groupId = theme.getSiteGroupId();
&nbsp; &nbsp; String name = ParamUtil.getString(request, "name");
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
&nbsp; &nbsp; LayoutLocalServiceUtil.addLayout(
&nbsp; userId,
groupId,
&nbsp; false,
0,
&nbsp; name,
&nbsp; null,
&nbsp; null,
&nbsp; LayoutConstants.TYPE_PORTLET,
&nbsp; false,
&nbsp; null,
&nbsp; new ServiceContext()
);
}</code></pre><br>But I can't seem to find a good example for the groups. I am confused with some parameters from the GroupLocalServiceUtil.addGroup()