<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Liferay 7.2 - How to add groups programmatically?</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=114847912" />
  <subtitle>Liferay 7.2 - How to add groups programmatically?</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=114847912</id>
  <updated>2026-04-04T21:28:21Z</updated>
  <dc:date>2026-04-04T21:28:21Z</dc:date>
  <entry>
    <title>RE: Liferay 7.2 - How to add groups programmatically?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114848258" />
    <author>
      <name>Fabio Carvalho</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114848258</id>
    <updated>2019-08-23T11:32:21Z</updated>
    <published>2019-08-23T11:32:21Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi Christoph,&lt;br&gt;&lt;br&gt;After some debugging I found what could be the correct way to create a group&amp;nbsp;programmatically. My method is the following:&lt;br&gt;&lt;pre&gt;&lt;code&gt;public void addGroup(ActionRequest request, ActionResponse response) throws IOException, PortletException, PortalException {
&amp;amp;nbsp; &amp;amp;nbsp; ThemeDisplay theme = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);&amp;amp;nbsp; &amp;amp;nbsp; long userId = theme.getUserId();
&amp;amp;nbsp; &amp;amp;nbsp; String name = ParamUtil.getString(request, "name");
&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; Map&amp;lt;locale, string&amp;gt; nameMap = new HashMap&amp;lt;locale, string&amp;gt;();
&amp;amp;nbsp; &amp;amp;nbsp; nameMap.put(LocaleUtil.US, name);
&amp;amp;nbsp; &amp;amp;nbsp; nameMap.put(LocaleUtil.PORTUGAL, name);
&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; GroupLocalServiceUtil.addGroup(
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; userId,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; GroupConstants.DEFAULT_PARENT_GROUP_ID,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; null,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; 0,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; GroupConstants.DEFAULT_LIVE_GROUP_ID,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; nameMap,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; null,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; GroupConstants.TYPE_SITE_OPEN,
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; false,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; null,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; true,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; true,&amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; new ServiceContext()
&amp;amp;nbsp; &amp;amp;nbsp; );
}&amp;lt;/locale,&amp;gt;&amp;lt;/locale,&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;I think this is creating a site/organization if I am not mistaken.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Fabio Carvalho</dc:creator>
    <dc:date>2019-08-23T11:32:21Z</dc:date>
  </entry>
  <entry>
    <title>RE: Liferay 7.2 - How to add groups programmatically?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114850009" />
    <author>
      <name>Christoph Rabel</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114850009</id>
    <updated>2019-08-23T11:29:51Z</updated>
    <published>2019-08-23T11:29:51Z</published>
    <summary type="html">What kind of groups?&lt;br /&gt;The term  group is a bit ambiguous in Liferay. Do you want to add Usergroups or do you want to add sites/organisations?</summary>
    <dc:creator>Christoph Rabel</dc:creator>
    <dc:date>2019-08-23T11:29:51Z</dc:date>
  </entry>
  <entry>
    <title>Liferay 7.2 - How to add groups programmatically?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114847911" />
    <author>
      <name>Fabio Carvalho</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114847911</id>
    <updated>2019-08-23T10:33:27Z</updated>
    <published>2019-08-23T10:33:27Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi,&lt;br&gt;&lt;br&gt;I am trying to add groups and layouts&amp;nbsp;programmatically in my custom portlet. Right now I am successfully adding layouts like this:&lt;br&gt;&lt;pre&gt;&lt;code&gt;public void addLayout(ActionRequest request, ActionResponse response) throws IOException, PortletException, PortalException {
&amp;amp;nbsp; &amp;amp;nbsp; ThemeDisplay theme = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; long userId = theme.getUserId();
&amp;amp;nbsp; &amp;amp;nbsp; long groupId = theme.getSiteGroupId();
&amp;amp;nbsp; &amp;amp;nbsp; String name = ParamUtil.getString(request, "name");
&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;
&amp;amp;nbsp; &amp;amp;nbsp; LayoutLocalServiceUtil.addLayout(
&amp;amp;nbsp;       userId, 
        groupId, 
&amp;amp;nbsp;       false, 
        0, 
&amp;amp;nbsp;       name, 
&amp;amp;nbsp;       null, 
&amp;amp;nbsp;       null, 
&amp;amp;nbsp;       LayoutConstants.TYPE_PORTLET, 
&amp;amp;nbsp;       false, 
&amp;amp;nbsp;       null, 
&amp;amp;nbsp;       new ServiceContext()
​​​​​​​    );
}&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;But I can't seem to find a good example for the groups. I am confused with some parameters from the&amp;nbsp;GroupLocalServiceUtil.addGroup() method. Is there are any good example of how to add groups&amp;nbsp;programmatically?&lt;br&gt;&lt;br&gt;Thank you!&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Fabio Carvalho</dc:creator>
    <dc:date>2019-08-23T10:33:27Z</dc:date>
  </entry>
</feed>
