See Sanity in action 👀 Join us for a live product demo + Q&A →

Using Object Scan to Find Grandparent Value

4 replies
Last updated: Jan 19, 2023
Hey again, I would like a conditional field based on a "grandparent" value. I've read that conditional fields wont accept promises though (so no groq commands i think). Is there a way to use the
{ parent, document, currentUser, value}
properties to find the grandparent value?
Jan 18, 2023, 5:04 PM
I guess I'll need another package for scanning the document object? Any recommendations?
Jan 18, 2023, 5:16 PM
You’d have to set something up to recursively check each field in the document for the parent in this case. We unfortunately don’t have any built in tooling for this 😞
Jan 18, 2023, 7:22 PM
user M
, I managed to use the package
to filter out the object keys and return the 'great grandparent' that I needed!
  name: "image",
  type: "image",
  title: "Image",

  hidden: ({document, parent}) => {
    const parents = objectScan(['++._key'], {
      joined: true,
      filterFn: ({ value }) => value === parent._key,
      rtn: 'parents'
    return !parents[2]?.useImages;
So good!
Jan 19, 2023, 12:36 AM
Great! Thanks for sharing your solution!
Jan 19, 2023, 12:44 AM – 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.

Categorized in