Writing to Sanity dropdown fields via script not displaying in Studio UI
Based on your description, it sounds like you have a string field with a dropdown (list) layout defined in your schema, but when you import data via script, the values aren't showing up in the Studio UI even though they appear in the document data.
The most common cause of this issue is a mismatch between the value you're writing and the values defined in your schema's options.list array.
In Sanity, when you define a dropdown field, you typically use something like:
{
name: 'myDropdownField',
type: 'string',
options: {
list: [
{title: 'Option One', value: 'option-one'},
{title: 'Option Two', value: 'option-two'}
],
layout: 'dropdown'
}
}The key issue: Your script must write the exact value (not the title) that's defined in the schema. If your data contains 'Option One' but your schema expects 'option-one', the Studio won't recognize it and the dropdown will appear blank.
Here's how to troubleshoot:
- Check your schema definition - Look at the
options.listarray for those fields and note the exactvalueproperties - Inspect your written data - Check what values your script is actually writing to those fields (you can use Vision plugin or check the raw JSON)
- Ensure exact match - The written value must exactly match one of the
valueproperties in your schema's list (case-sensitive)
For example, if your schema has:
options: {
list: ['draft', 'published', 'archived']
}Your script must write exactly 'draft', 'published', or 'archived' - not 'Draft' or any variation.
Additional tip: If you're migrating from another system, you might need to create a mapping function in your script to transform your source values into the values expected by your Sanity schema. Something like:
const statusMap = {
'Draft': 'draft',
'Published': 'published',
'Archived': 'archived'
}
const sanitizedData = {
...yourData,
status: statusMap[yourData.status] || 'draft'
}If you share your schema definition for one of those dropdown fields and an example of the data you're writing, I can help pinpoint the exact mismatch!
Show original thread10 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.