# Iterating through selected grouped items

**URL:** <https://forums.creativeclouddeveloper.com/t/iterating-through-selected-grouped-items/392>\
**Category:** UXP Plugin API\
**Tags:** javascript\
**Created:** [November 12, 2018, 8:40am UTC](https://forums.creativeclouddeveloper.com/t/iterating-through-selected-grouped-items/392 "2018-11-12T08:40:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![callmeahab](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@callmeahab](https://forums.creativeclouddeveloper.com/u/callmeahab)\
**Post date:** [November 12, 2018, 8:40am UTC](https://forums.creativeclouddeveloper.com/t/iterating-through-selected-grouped-items/392/1 "2018-11-12T08:40:53Z")

</div>

As the title says, I’m having trouble iterating through selected records, more specifically when they’re in nested groups, and the api documentation seems really vague on this topic.

Since I need to edit each of the selected items, I use commands.ungroup(), and that works fine when there are only items in groups. However this commands ungroups just the first level of groups, so I need to use it again, but at that point all selected items are available only in `selection.items`, and there’s no indication to which group these items belong. Neither do I seem to be able to assign these values to an object and recreate all the grouping.

Does anyone have a suggestion on how to achieve this?

Thanks in advance
