Jul 13, 2022 07:57 AM
Hi everyone,
I’m a new user on airtable and I would like to create a table which contains a number field type, but when I run the script, I got this notification :
We have a table A containing the list of clients we work with and each client has their own table. So when we add a new record in this table A, we are supposed to create a new table for this new client, that’s why we need this script.
In the part of script below, I have those lines that I think is the right syntax to create a new table for the new client.
const tableName = await input.textAsync(‘Choose the name of this new client’s table’);
const primaryFieldName = await input.textAsync(‘Enter the name of the primary field’);
const primaryFieldType = await selectFieldAsync(‘Choose the right type of the field’); // selectFieldAsync is a custom async function that prompt the user to select the type of the field
let tableId = await base.createTableAsync(tableName, [{
name: primaryFieldName, //
type: primaryFieldType,
options: getFieldTypeOptions(primaryFieldType), // getFieldTypeOptions is a custom function
},{
name: “Civ”,
type: “singleLineText”,
},{
name: “Name”,
type: “singleLineText”,
},{
name: “Siret”,
type: “number”,
}]);
async function selectFieldTypeAsync(label){
return input.buttonsAsync(label, [
{label: ‘Text’, value: ‘singleLineText’},
{label: ‘Multiline Text’, value: ‘multilineText’},
{label: ‘PhoneNumber’, value: ‘phoneNumber’},
{label: ‘Number’, value: ‘number’},
{label: ‘Email’, value: ‘email’},
{label: ‘URL’, value: ‘url’},
]);
}
function getFieldTypeOptions(fieldType) {
switch (fieldType) {
case ‘singleLineText’:
case ‘multilineText’:
case ‘email’:
case ‘url’:
return null;
case ‘phoneNumber’:
return null;
case ‘number’:
return {precision: 5}
default:
throw new Error (‘Unexpected field type’)
}
}
May someone help me with the right syntax on the creation of the Number type field ?
Thank’s in advance.
Solved! Go to Solution.
Jul 13, 2022 08:49 AM
When creating a number field, you need to specify the precision in the options for the field. The format is in the documentation.
Jul 13, 2022 08:49 AM
When creating a number field, you need to specify the precision in the options for the field. The format is in the documentation.
Jul 15, 2022 02:26 AM
It works !
Thanks a lot. :winking_face: