Help

Re: Input.config.select -> populate labels based on input.confg.field?

1393 1
cancel
Showing results for 
Search instead for 
Did you mean: 
LooselySutble
4 - Data Explorer
4 - Data Explorer

I want to write a small script that updates all status-fields in a given view.
Let’s say I have a view with tasks. Tasks have a status-field ( single-select: ‘new’, ‘busy’, ‘done’).
My script should update all status-fields for all tasks in a given view.

With input.config, I can select the base, view and field (status).
But I can’t find a way to select the new value of status for all those tasks.
Is there a way to accomplish this?

Because I want this script to be as generic as possible, I don’t want to hardcode any values. Idealiter, selecting done should return the id for that field. Something like.

let config = input.config({
    items: [
        input.config.table('selectedTable', {
            label: 'Table to use',
            description: 'Pick any table in this base!',
        }),
        input.config.view('selectedView', {
            label: 'View inside the above table',
            parentTable: 'selectedTable',
        }),
        input.config.field('selectedField', {
            label: 'Field from which to select values',
            parentTable: 'selectedTable',
        }),
        input.config.number('selectedOption', {
            **HELP NEEDED FOR THIS PART!**
        })
    ]
});

let option = selectedField.options.choices[selectedOption].id

// select all records in this view

let allrecords = await selectedView.selectRecordsAsync({

    fields: [selectedfield]

})

// update

for (let record of allrecords.records) {

    console.log('updating:' + record.name)

    await selectedtable.updateRecordAsync(record,{[selectedField.id]: {id: option}})

}

Is this even feasible?

3 Replies 3

Here are some options:

If the script will always be run from a button field, and the choice could vary from run to run, have the script ask the user for the choice at runtime. The script can get the choices from the field and then have the user click a button to pick the choice.

If the script should always use the same choice (until configured differently), have the script settings input the choice as text (not a number). The user entering the text will be responsible for making sure that the text is a valid choice.

hi Kuovonne

thank you for your reply.
I am just taking my first steps into AirTable custom scripting, so I have no idea how to start on either of your proposed solutions :slightly_smiling_face:

Currently, I have a variation on your second approach, by asking the ‘number’ of the desired value, (first, second, third), as user text-input can never be trusted :slightly_smiling_face:

How would I start to implement your first suggestion, aka asking for a choice at runtime?

User text input is about as trustworthy as user number input. If a user enters a number that is greater than the number of options, your script won’t work. A user is far more likely to know the name of the desired choice versus the index (especially since index values start at zero).

Here is the documentation for getting input from the user via a button at runtime.