# I don't know how to use \`index.getObjectByRef\`

**URL:** https://community.silverbullet.md/t/i-dont-know-how-to-use-index-getobjectbyref/4189
**Category:** Lua
**Created:** [June 2, 2026, 2:29pm UTC](https://community.silverbullet.md/t/i-dont-know-how-to-use-index-getobjectbyref/4189 "2026-06-02T14:29:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![drhayes](https://community.silverbullet.md/user_avatar/community.silverbullet.md/drhayes/32/1390_2.png) [@drhayes](https://community.silverbullet.md/u/drhayes)
#### Post date: [June 2, 2026, 2:29pm UTC](https://community.silverbullet.md/t/i-dont-know-how-to-use-index-getobjectbyref/4189/1 "2026-06-02T14:29:11Z")

</div>

Everything I pass in returns `nil`.

For example: `index.getObjectByRef('index', 'page', 'index')` in my space, which I would think would get me my index page, returns `nil`. I _think_ I know the difference between the `page` argument and the `ref` argument; in this case they look pretty similar since what I'm grabbing is a `page` vs. a `link` or whatnot. But every variation I've tried has returned `nil` and I can't find a working space lua example.

But my real use case is I'm trying build a haircut tracker, something that can answer, "How long has it been since I've had a haircut?" I want to solve this by adding a `[[Haircut]]` link in my daily journal, then creating a command I can run that counts the days since the last haircut link.

I could also do it by adding a page attribute, or something in the frontmatter, but adding the link is pretty seamless since I'm writing about my day already -- no need to drop into programmer-mode.

I'm pretty sure I know how to query for the link, but I want to turn the `page` of the link object into a real page. Once I have that I can check when the page was created and start doing fun date math to count the days.

---

<div class="post-metadata">

### Author: ![Mike](https://community.silverbullet.md/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@Mike](https://community.silverbullet.md/u/Mike)
#### Post date: [June 2, 2026, 2:53pm UTC](https://community.silverbullet.md/t/i-dont-know-how-to-use-index-getobjectbyref/4189/2 "2026-06-02T14:53:05Z")

</div>

Why don't you:

`${query[[from o = index.objects("link") where o.destination == "haircut" order by o.page desc limit 1 select o.page]]}`

Assuming you Journal page has the date in it, you only need extract the data from your journal pagename.

---

<div class="post-metadata">

### Author: ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)
#### Post date: [June 2, 2026, 3:12pm UTC](https://community.silverbullet.md/t/i-dont-know-how-to-use-index-getobjectbyref/4189/3 "2026-06-02T15:12:43Z")

</div>

> [@drhayes](#):
>
> For example: `index.getObjectByRef('index', 'page', 'index')` in my space, which I would think would get me my index page, returns `nil`.

For me it returns a table?

```auto
${index.getObjectByRef("index", "page", "index")}

```

Gives me

 ![CleanShot 2026-06-02 at 17.09.36](https://community.silverbullet.md/uploads/default/original/2X/4/41467edf53c02fac0e7ee52cbaab68f1c4c30817.png)

That said, a query in lines of what @Mike is likely what you want to do. getObjectByRef is more of an internal API to the the quickest possible lookup of an object where you already know exactly on what page it appeared, the tag and ref, which is a rare occurence.

---

<div class="post-metadata">

### Author: ![drhayes](https://community.silverbullet.md/user_avatar/community.silverbullet.md/drhayes/32/1390_2.png) [@drhayes](https://community.silverbullet.md/u/drhayes)
#### Post date: [June 2, 2026, 4:18pm UTC](https://community.silverbullet.md/t/i-dont-know-how-to-use-index-getobjectbyref/4189/4 "2026-06-02T16:18:56Z")

</div>

> [@zef](#):
>
> For me it returns a table?

Okay, [PEBKAC](https://en.wikipedia.org/wiki/User_error)! In my main space, it returns `nil`. In my work space, it returns a table! That is a deeply weird thing that I'll shelve and figure out later. Seems like my main space is having issues with page names, or something? Every reasonable example I tried in my work space was just fine. Cool beans, I'm good.

As for parsing the date out of the title, I'd rather rely on a data attribute than a naming scheme, if possible -- my preference is for structured data, if it's available. But thanks for the suggestion!

---

<div class="post-metadata">

### Author: ![drhayes](https://community.silverbullet.md/user_avatar/community.silverbullet.md/drhayes/32/1390_2.png) [@drhayes](https://community.silverbullet.md/u/drhayes)
#### Post date: [June 2, 2026, 5:08pm UTC](https://community.silverbullet.md/t/i-dont-know-how-to-use-index-getobjectbyref/4189/5 "2026-06-02T17:08:44Z")

</div>

Did some investigating, figured out that my personal space was running 2.5.2 and my work space was running 2.8.1. Updated my personal space to latest and the world makes sense again, I'm getting a table when looking for my index page by ref.

Thanks again, all!
