# Create sub group to a group using JAVA SDK

**URL:** <https://community.cumulocity.com/t/create-sub-group-to-a-group-using-java-sdk/609>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [January 29, 2024, 4:17pm UTC](https://community.cumulocity.com/t/create-sub-group-to-a-group-using-java-sdk/609 "2024-01-29T16:17:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arsalan\_Mahmood\_Sidd](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/arsalan_mahmood_sidd/32/30487_2.png) [@Arsalan\_Mahmood\_Sidd](https://community.cumulocity.com/u/Arsalan_Mahmood_Sidd)\
**Post date:** [January 29, 2024, 4:17pm UTC](https://community.cumulocity.com/t/create-sub-group-to-a-group-using-java-sdk/609/1 "2024-01-29T16:17:16Z")

</div>

#### _ **Product/components** used and **version/fix** level:_

10.18

#### _Detailed explanation of the problem:_

Hi Guys!  
I want to create a sub group to a group using the Java SDK. I tried the following

```auto
subscriptionsService.runForTenant(subscriptionsService.getTenant(), () -> {
				ManagedObjectRepresentation response = inventoryApi.create(asset);
				LOG.info("Group created with id:" + response.getId().getValue());
				

				// make this group as child of unsorted
				GId gid = GId.asGId(unsortedGroupMoId.get(subscriptionsService.getTenant()));
				ManagedObject managedObjectApi = inventoryApi.getManagedObjectApi(gid);
				managedObjectApi.addChildAsset(ManagedObjects.asManagedObject(response.getId()));
			});

```

I get the error that the id is not updatable. Does anyone know how can I assign the newly created group as the child of the group whose Gid i extract in the code above.

#### _Error messages / **full error** message screenshot / **log** file:_

execution of task failed within tenant : XXXXX - Http status code: 422  
{error=“undefined/validationError”,message=“Following fields are not updateable: id”,info=“[https://www.cumulocity.com/guides/reference/rest-implementation//#a-name-error-reporting-a-error-reporting",details="null](https://www.cumulocity.com/guides/reference/rest-implementation//#a-name-error-reporting-a-error-reporting%22,details=%22null)”}  
tenant: XXXXX user: service\_c2c-integration

#### _Question related to a **free trial** , or to a **production (customer)** instance?_

  

* * *

Arsalan Mahmood Siddiqi

[Software AG Professional Services](https://www.softwareag.com/en_corporate/resources/services/professional-services.html)

[![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/c/3/c3a93a2618e4708f51be40fe2e142061f7c4edc7.jpeg)](https://www.softwareag.com/en_corporate/resources/services/fast-track-services.html)

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [January 29, 2024, 4:31pm UTC](https://community.cumulocity.com/t/create-sub-group-to-a-group-using-java-sdk/609/2 "2024-01-29T16:31:27Z")

</div>

You can skip the first step and just execute the second call with the GID of the source group where you want to attach the to-be-created sub-group to.  
Haven’t tested it but this is how I understand it.

```auto
ManagedObject managedObjectApi = inventoryApi.getManagedObjectApi(gid); //GID of the source group 
managedObjectApi.addChildAsset(<<ManagedObjectReprensentationToBeCreated>>);

```

---

<div class="post-metadata">

**Author:** ![Arsalan\_Mahmood\_Sidd](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/arsalan_mahmood_sidd/32/30487_2.png) [@Arsalan\_Mahmood\_Sidd](https://community.cumulocity.com/u/Arsalan_Mahmood_Sidd)\
**Post date:** [January 29, 2024, 5:03pm UTC](https://community.cumulocity.com/t/create-sub-group-to-a-group-using-java-sdk/609/3 "2024-01-29T17:03:56Z")

</div>

This worked! There was another function called addChildAsset **s**

```auto
				// make this group as child of unsorted
				GId gid = GId.asGId(unsortedGroupMoId.get(subscriptionsService.getTenant()));

				ManagedObject managedObjectApi = inventoryApi.getManagedObjectApi(gid);
				managedObjectApi.addChildAssets(response.getId());

```

  

* * *

Arsalan Mahmood Siddiqi

[Software AG Professional Services](https://www.softwareag.com/en_corporate/resources/services/professional-services.html)

[![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/c/3/c3a93a2618e4708f51be40fe2e142061f7c4edc7.jpeg)](https://www.softwareag.com/en_corporate/resources/services/fast-track-services.html)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [July 27, 2024, 5:04pm UTC](https://community.cumulocity.com/t/create-sub-group-to-a-group-using-java-sdk/609/4 "2024-07-27T17:04:24Z")

</div>

Closed on July 27, 2024, 5:04pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
