How to create new record and select values for single select fields

Hi. I would like to create a template script that will create a bunch of rows for me.

Two fields in my table are single select fields. The fields are ‘Type’ and ‘Image Order’.

How do I choose existing values in those fields? See my code below.

I’m getting the following error:

Error: Can’t create records. invalid cell value for field ‘Type’. Cell value has invalid format: must be an object Single select field value must be an object with at least one of ‘id’ or ‘name’ as a property.

// Create three records in the Vendors and Contacts table
let table = base.getTable("Detail Page Resources");
let recordIds = await table.createRecordsAsync([
    {
        fields: {
            'Type': 'Primary Image',
            'Image Order': '1',
            
        },
    },
    // Specifying an empty fields object will create a new record with no cell values set
    {
        fields: {},
    },
]);
output.text("Created " + recordIds.length + " records!");

//Field 'Type' id is fldulSwbmghIAHeUU
//Primary Image single select id is selvmIA08iXpZt3ba

Theres an “Expense Tracking” script by @Jeremy_Oglesby that I was able to modify to fit my needs to single select population. Check it out and see if what he has there will fit your needs. It’s over in the “Show and Tell” category I think

@EKBrang’s reference:

I figured it out. I wasn’t setting the options for the SingleSelect object correctly. Here is the correct code

// Create three records in the Vendors and Contacts table
let orders = base.getTable('Order Group Summary');
let table = base.getTable("Detail Page Resources");

/* Pick from a table */
let table2 = base.getTable("Products/Variations");
let product = await input.recordAsync('Pick a product to create new row template', table2);

if (product) {
    output.text(`You picked ${product.getCellValueAsString("Short Name")}`);   


let recordIds = await table.createRecordsAsync([
    {
        fields: {
        'Type': { name: 'Primary Image 1' },
        'Product': [{id: product.id}]
        },
        
    },
    {
        fields: {
        'Type': { name: 'Primary Image 2' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Primary Image 3' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Primary Image 4' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Primary Image 5' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Primary Image 6' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Primary Image 7' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Variation Swatch' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Title' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Bullet Point 1' },
        'Product': [{id: product.id}]
        },
    },
        {
        fields: {
        'Type': { name: 'Bullet Point 2' },
        'Product': [{id: product.id}]
        },
    }, 
    {
        fields: {
        'Type': { name: 'Bullet Point 3' },
        'Product': [{id: product.id}]
        },
    },   
    {
        fields: {
        'Type': { name: 'Bullet Point 4' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Bullet Point 5' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'Description' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'EBC Logo' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'EBC Banner' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'EBC Image 1' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'EBC Image 2' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'EBC Image 3' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'EBC Image 4' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'EBC Image 5' },
        'Product': [{id: product.id}]
        },
    },
    {
        fields: {
        'Type': { name: 'EBC Image 6' },
        'Product': [{id: product.id}]
        },
    },
]);
output.text("Created " + recordIds.length + " records!");
}
else {
    output.text("You didn't select a record. Please start again.");
}
1 Like