Skip to main content
Solved

Auto generate a new record ID

  • August 29, 2024
  • 2 replies
  • 281 views

Forum|alt.badge.img+3

How can I automatically generate a new record ID in Airtable that continues sequentially from the last number in the existing data?

Best answer by Saravanan_009

To automatically generate a new record ID that continues sequentially in Airtable, you can use a combination of a formula field and a script. Here’s a step-by-step guide:

Example script:

let table = base.getTable("Your Table Name");
let query = await table.selectRecordsAsync();

let maxId = 0;
for (let record of query.records) {
let id = record.getCellValue("Record ID");
if (id > maxId) {
maxId = id;
}
}

let newId = maxId + 1;
await table.createRecordAsync({
"Record ID": newId,
// Add other fields as needed
});

This script will ensure that each new record gets a unique and sequential ID based on the highest existing ID.

2 replies

TheTimeSavingCo
Forum|alt.badge.img+31

Hmm, if the autonumber field doesn't work you might need to use scripting I'm afraid (https://support.airtable.com/docs/number-based-fields-in-airtable#autonumber-fields)





Saravanan_009
Forum|alt.badge.img+17
  • Inspiring
  • Answer
  • August 30, 2024

To automatically generate a new record ID that continues sequentially in Airtable, you can use a combination of a formula field and a script. Here’s a step-by-step guide:

Example script:

let table = base.getTable("Your Table Name");
let query = await table.selectRecordsAsync();

let maxId = 0;
for (let record of query.records) {
let id = record.getCellValue("Record ID");
if (id > maxId) {
maxId = id;
}
}

let newId = maxId + 1;
await table.createRecordAsync({
"Record ID": newId,
// Add other fields as needed
});

This script will ensure that each new record gets a unique and sequential ID based on the highest existing ID.