Skip to main content
Solved

Missing option in creating table with a number type field


  • New Participant
  • 1 reply

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.

Best answer by kuovonne

When creating a number field, you need to specify the precision in the options for the field. The format is in the documentation.

View original

2 replies

kuovonne
Forum|alt.badge.img+17
  • Inspiring
  • 5983 replies
  • Answer
  • July 13, 2022

When creating a number field, you need to specify the precision in the options for the field. The format is in the documentation.


  • Author
  • New Participant
  • 1 reply
  • July 15, 2022

It works !


Thanks a lot. :winking_face:


Reply