Unlock seamless workflows and faster delivery with our latest releases – get the details

Difficulty in passing initial values to singletons in Structure Builder.

8 replies
Last updated: Aug 24, 2023
Is there a way to pass ininitalvalues / initialvaluetemplates to singletons in structurebuilder ?

 S.document()
        .schemaType(schemaTypeName)
        .documentId(docId)
        .initialValueTemplate(templateId)
Doing the above doesn’t work
Aug 23, 2023, 11:20 AM
Should be possible according to the docs . Have you followed the steps there?
Aug 23, 2023, 12:10 PM
This shows how to do it for documentTypeList. But I’m creating a singleton (document), so I’m never clicking on the “Create new” button.I.e. “initialValueTemplates” is not available on document, only on documentList/documentTypeList
Aug 23, 2023, 12:32 PM
I have a schematype which is being used in a fixed amount of places (e.g. 10). Where I have hardcoded the id. I just want the ability to pass in a set of initial values for each of the instances I’m creating.
Aug 23, 2023, 12:34 PM
The code that you provided earlier seems to work in my test.Can you check the following:
1. Value for
schemaTypeName
is correct and matches the schema name2. Value for
docId
is correct and matches the type of the document matches
schemaTypeName
3. Value for
templateId
is correct and the
schemaType
specified there matches the one in (1)4. Delete the existing singleton document and see if the new one has the initial values
Aug 23, 2023, 1:44 PM
hm, how do I delete a singleton though ?
Aug 24, 2023, 8:16 AM
Are you unable to delete it from the menu?
Aug 24, 2023, 8:39 AM
No sorry you’re right. That was an issue on my side.
Deleting automatically recreates a doc with the initial values
🙂
Aug 24, 2023, 8:46 AM
thanks 🙂
Aug 24, 2023, 8:46 AM

Sanity– build remarkable experiences at scale

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

Was this answer helpful?