Help

Welcome to the Airtable Community! If you're new here, check out our Getting Started area to get the most out of your community experience.

Move record table to other table

Topic Labels: Scripting extentions
433 2
cancel
Showing results for 
Search instead for 
Did you mean: 

Hi,
I’ve a simple code to move checked record from table to other table:

let foraccept = base.getTable(“For Accept”);
let plugins = base.getTable(“Plugins”);
let result = await foraccept.selectRecordsAsync();
for (let record of result.records) {
if (record.getCellValue(“Accepted”)) {
await plugins.createRecordsAsync([
{
fields: {
‘Name’: record.getCellValue(“Name”),
‘Website’: record.getCellValue(“Website”),
‘Type’: record.getCellValue(“Type”),
},
}
]);
await foraccept.deleteRecordAsync(record.id);
}
}

My problem is: How i get values from single or multiple select? (Field “Type”) → ‘Type’: record.getCellValue(“Type”).

It is possible?

2 Replies 2

Hey @Mariusz_Jankowski :winking_face:
Try this:

let foraccept = base.getTable("For Accept");
let plugins = base.getTable("Plugins");
let result = await foraccept.selectRecordsAsync();
let typeTypedField = foraccept.getField('Type')
const typeTypedFieldOptions = typeTypedField !== null ? typeTypedField.options.choices : [];

for (let record of result.records) {
    let matchTypeField = record.getCellValue('Type');
    let matchType = matchTypeField ? matchTypeField.name : '';
    let newValue1 = typeTypedFieldOptions.find(o => o.name === matchType);
    if (record.getCellValue("Accepted")) {
    await plugins.createRecordsAsync([
{
    fields: {
    "Name": record.getCellValue("Name"),
    "Website": record.getCellValue("Website"),
    "Type": {name : newValue1.name} 
    },
}
]);
await foraccept.deleteRecordAsync(record.id);
	}
}

everything works, thank you;)