👀 See Sanity in action: Watch product demo now →

Can the results of a query in documentList be reused inside the function?

3 replies
Last updated: Sep 19, 2020
Can the results of a query in
documentList
be reused inside the function? For example, I’d like the title here to say like “13 Properties with Inspection Times” or whatever the count of the query is…

S.documentList()
  .schemaType('property')
  .title('Properties with Inspection Times')
  .filter(
      '_type == "property" && count(inspectionTimes) > 0'
  )
Sep 19, 2020, 7:34 AM
That’s not possible at the moment. But since you can run promises/observables, you can do the query in the structure builder… structure and use the data where you need it.
Here’s an example where we fetch counts in the icons:
https://sanity-io.slack.com/archives/CGKNRPC80/p1593460636120200?thread_ts=1593460050.120000&cid=CGKNRPC80
And another where we use the documentstore to list out tickets by their tags (that can be adapted to your use case):
https://github.com/sanity-io/community-studio/blob/master/deskStructure.js#L143
Sep 19, 2020, 9:11 AM
That’s not possible at the moment. But since you can run promises/observables, you can do the query in the structure builder… structure and use the data where you need it.
Here’s an example where we fetch counts in the icons:
https://sanity-io.slack.com/archives/CGKNRPC80/p1593460636120200?thread_ts=1593460050.120000&cid=CGKNRPC80
And another where we use the documentstore to list out tickets by their tags (that can be adapted to your use case):
https://github.com/sanity-io/community-studio/blob/master/deskStructure.js#L143
Sep 19, 2020, 9:11 AM
Okay cool. Yeah after posting I figured maybe I could do the query elsewhere and pass in the results that way. These code examples help, thanks!
Sep 19, 2020, 9:13 AM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.