Help

Move record table to other table

Topic Labels: Scripting extentions
1220 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Mariusz_Jankows
5 - Automation Enthusiast
5 - Automation Enthusiast

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
Mariusz_S
7 - App Architect
7 - App Architect

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;)