Help

Re: Error problem

77 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Peezy
5 - Automation Enthusiast
5 - Automation Enthusiast

Screenshot 2024-11-10 at 11.14.13 PM.png

Hey can someone tell me why I keep getting a error I tried so many different ways that I know but i seem to can't figure It out😩

4 Replies 4
dilipborad
9 - Sun
9 - Sun

Hello @Peezy,
Let's first understand how airtable Scripting works.
Airtable has 2 types of scripting. 1) Automation Scripting 2) Extension Scripting.

1) Automation Scripting: https://support.airtable.com/docs/run-a-script-action#run-a-script-action-limits
As this is run into Airtable's server that's why restrict many basic logging objects. 
In your current case use

 

console.log('your string')

 

2) The output.text() which can be easily used on Airtable Extension. That is totally run on our local browser so it can able to execute that.

Try to understand the difference between them, then it will be easy to use.
👍

Peezy
5 - Automation Enthusiast
5 - Automation Enthusiast

Screenshot 2024-11-13 at 12.05.02 AM.png

let table = base.getTable("PS5"); // Replace with your table name
let query = await table.selectRecordsAsync();
let ticketsField = "Tickets"; // The field that contains the number of tickets

// Collect the records that need to be duplicated
let recordsToDuplicate = [];

for (let record of query.records) {
let numTickets = record.getCellValue(ticketsField);

// If Tickets field is greater than 1, add it to the list to be duplicated
if (numTickets && numTickets > 1) {
recordsToDuplicate.push(record);
}
}

// Now we loop through the recordsToDuplicate list and create the new records
for (let record of recordsToDuplicate) {
let numTickets = record.getCellValue(ticketsField);

// Create the specified number of new records (minus 1 since the original record remains)
for (let i = 0; i < numTickets - 1; i++) { // Subtract 1 to avoid duplicating the original record
let newRecordData = {};

// Loop through all fields and copy values to the new record (excluding the Tickets field)
for (let field of table.fields) {
if (field.name !== ticketsField) {
newRecordData[field.name] = record.getCellValue(field.name);
}
}

// Create the new record
await table.createRecordAsync(newRecordData);
}
}

console.log("New records created successfully!");

 

Peezy
5 - Automation Enthusiast
5 - Automation Enthusiast

How can I get this script to only create new record lines for only the amount of the "Tickets" ???

The script keeps creating new record lines until I go in and shut the automations off

Hello @Peezy,
I think you hit circular reference on the Automation trigger call.
It's something like Initially you create new record on a your table and you've setup trigger to run that automation.

Then during the process of that automation, it creates a new record in the same table in that case that same automation is triggered again.
Read more at here https://support.airtable.com/docs/troubleshooting-airtable-automations#unexpected-automation-output

👍