Writing to Sanity dropdown fields via script not displaying in Studio UI

10 replies
Last updated: Nov 30, 2025
Hello all 🙂I’m in the process of writing content to Sanity Studio using a script to create new documents. So far I have been able to adjust the shape of my data as necessary, and write new documents successfully. That is except for two fields I have which, in my Sanity Studio, are displayed as a dropdown layout choice of two options each. Even though my field names match, and the data appears to be there when I inspect a particular document, it is not visible in the UI and my dropdown remains blank, instead of displaying the data I have written.
Has anyone had any experience with this?
I’m wondering how to get my data appearing in that dropdown field correctly in the studio.
AI Update

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:

  1. Check your schema definition - Look at the options.list array for those fields and note the exact value properties
  2. 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)
  3. Ensure exact match - The written value must exactly match one of the value properties 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 thread
10 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.

Was this answer helpful?