Saskia Bobinska
Senior Support Engineer @Sanity
Only return a value when a condition is fulfilled
*[
_type == "article"
&& (
!defined(image.altText)
|| (
count(body[_type == 'image' && !defined(altText)]) > 0
)
)
] | order(publishedAt desc) {
_id,
title,
// Condition 1 - document level
!defined(image.altText) => {
'image': image.asset,
},
// Condition 2 - inside portable text
count(body[_type == 'image' && !defined(altText)]) > 0 => {
"bodyImage": body[_type == 'image']
},
}
Let's assume you want to check which images in your documents have an altText
set. These image fields are either on the first document level or in the body
field (portable text) as a custom block
of type image
. To get all documents with images without an altText
you can use conditional value fetching in your query.
You can setup conditions using this logic in GROQ:
CONDITION => { VALUES_YOU_WANT},
Senior Support Engineer @Sanity
Use a migration script to update all references from one document to another
Go to Update references via Content Migration scriptIf you install plugins or other packages with conflicting (peer) dependencies, you can use this useful workaround to unblock yourself.
Go to What to do when Studio crashes due to conflicts in dependency versions?When creating custom document actions, it can be necessary to check, wether all validation rules are full-filled.
Go to Use the validation status of a document in your custom document actionsIf you want to make it possible to use parameterised initialValue templates in reference fields, this is how!
Go to Create a new reference document with parameterised initial Values