Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

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

3799 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Chris_Guthrie
7 - App Architect
7 - App Architect

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
4 Replies 4
EKBrang
4 - Data Explorer
4 - Data Explorer

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:

Chris_Guthrie
7 - App Architect
7 - App Architect

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.");
}
Hector_J_Carr
5 - Automation Enthusiast
5 - Automation Enthusiast

In case it’s not a single select field, it’s only a number field, how can the field type be established? Because I keep getting the error that “Error: Field “fldvL6Nlx8t0sm9MK” cannot accept the provided value.”