# How do I get the containing group of a record via AppleScript?

**URL:** <https://discourse.devontechnologies.com/t/how-do-i-get-the-containing-group-of-a-record-via-applescript/87219>\
**Category:** Automation\
**Created:** [June 23, 2026, 12:50pm UTC](https://discourse.devontechnologies.com/t/how-do-i-get-the-containing-group-of-a-record-via-applescript/87219 "2026-06-23T12:50:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ustad](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/u/e274bd/32.png) [@ustad](https://discourse.devontechnologies.com/u/ustad)\
**Post date:** [June 23, 2026, 12:50pm UTC](https://discourse.devontechnologies.com/t/how-do-i-get-the-containing-group-of-a-record-via-applescript/87219/1 "2026-06-23T12:50:16Z")

</div>

I’m working on a larger script to move a selected record (group or document) to a particular location in a database, and I need help with what seems like it should be a simple AppleScript idiom. I’ve had success with this:

**`move`** ` `_`record`_` theRecord to` **`the`** `incoming group` **`of`** ` `_`database`_` "Inbox"`

in a script that refiles a misplaced record back into the Inbox.

But I’m trying to to move a particular selected record to its “grandparent” group: that is, the group that contains the group that contains the selected record, and I can’t seem to avoid the error:

“Can’t get parent of selected record” (1728)

I have tried a few different approaches to getting the parent group of the selected record (where in the following `my_record` has been set to the _`selected record`_):

e.g.,

**`set`** `the_parent` **`to`** ` ` **`the`** ` `_`parent`_` ` **`of`** ` my_record`

or (in case I need to treat parents like a list)

**`set`** `the_parent` **`to`** ` ` **`the`** ` ` **`first`** ` `_`parent`_` ` **`of`** ` my_record`

or (in case I need to be accessing a property)

**`set`** `the_parent` **`to`** ` (` **`get`** ` ` **`the`** `location` **`of`** ` my_record)`

or

**`set`** `the_parent` **`to`** ` ` **`the`** `location group` **`of`** ` my_record`

or even

**`set`** `the_parent` **`to`** ` ` **`the`** ` `_`parent`_` ` **`whose`** ` `_`child`_` ` **`is`** ` my_record`

I must be missing something obvious about correctly accessing the parent of a record. What’s the correct way to get the parent or containing group of a currently selected record?

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 23, 2026, 2:11pm UTC](https://discourse.devontechnologies.com/t/how-do-i-get-the-containing-group-of-a-record-via-applescript/87219/2 "2026-06-23T14:11:48Z")

</div>

`parent` is not a wise choice here. An item can have multiple parents so don’t think about it relative to where a document is.

Here is a naïve but effective way to do the specific thing you’re asking about…

```auto
tell application id "DNtp"
	if (selected records) is {} then return
	return name of (location group of (location group of selected record 1))
end tell

```

---

<div class="post-metadata">

**Author:** ![ustad](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/u/e274bd/32.png) [@ustad](https://discourse.devontechnologies.com/u/ustad)\
**Post date:** [June 23, 2026, 2:31pm UTC](https://discourse.devontechnologies.com/t/how-do-i-get-the-containing-group-of-a-record-via-applescript/87219/3 "2026-06-23T14:31:36Z")

</div>

> [@BLUEFROG](#):
>
> ```auto
> if (selected records) is {} then return
> return name of (location group of (location group of selected record 1))
> 
> ```

Thanks! This gives me what I needed.

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 23, 2026, 2:56pm UTC](https://discourse.devontechnologies.com/t/how-do-i-get-the-containing-group-of-a-record-via-applescript/87219/4 "2026-06-23T14:56:46Z")

</div>

You’re welcome.
