Help

LongTextFields Error

Topic Labels: Scripting
355 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Murgy91
4 - Data Explorer
4 - Data Explorer

I am receiving the below error;

O: Can't create field: invalid field config. Creating or updating options for longText fields is not supported at this time. at main on line 31

Can Airtable not support creating a Long Text Field? I might be missing something;

 

 

let table = base.getTable("Report");

// List of fields to duplicate, with their types
let fieldsToDuplicate = [
    { name: "Act Name - GA 1", type: "singleLineText" },
    { name: "Additional Comments - GA 1", type: "longText" },
    { name: "Guest Artiste Show - GA 1", type: "multipleRecordLinks" },
    { name: "Versatility - GA 1", type: "rating" },
    { name: "Guests Socialization - GA 1", type: "rating" },
    { name: "Audience Engagement, Adaptability - GA 1", type: "rating" },
    { name: "Material Quality, Originality - GA 1", type: "rating" },
    { name: "Professionalism and Reliability - GA 1", type: "rating" },
    { name: "Adhere to Dress Code - GA 1", type: "rating" },
    { name: "End of Show Audience - GA 1", type: "percent" },
    { name: "Start of Show Audience - GA 1", type: "percent" },
    { name: "Performance Style & Stage Presence - GA 1", type: "rating" }
];

// Number of times to duplicate
let duplicates = 3;

for (let i = 0; i < duplicates; i++) {
    for (let field of fieldsToDuplicate) {
        let originalName = field.name;
        let suffixNumber = i + 2; // Start suffix from GA 2
        let newName = originalName.replace("- GA 1", `- GA ${suffixNumber}`);

        // Create the new field based on type
        if (field.type === "longText") {
            // Directly use createFieldAsync with only name and type for longText
            await table.createFieldAsync(newName, field.type);
        } else if (field.type === "singleLineText" || field.type === "percent") {
            await table.createFieldAsync(newName, field.type);
        } else if (field.type === "rating") {
            // Ratings require a max value
            await table.createFieldAsync(newName, field.type, { max: 5 });
        } else if (field.type === "multipleRecordLinks") {
            // MultipleRecordLinks require a linked table ID
            await table.createFieldAsync(newName, field.type, {
                linkedTableId: table.id // Assuming links to the same table
            });
        }

        // Copy data from the original field to the new field
        let query = await table.selectRecordsAsync();
        for (let record of query.records) {
            let value = record.getCellValue(originalName);

            // Ensure the value is compatible with the field type
            if (field.type === "singleLineText" || field.type === "longText") {
                value = typeof value === "string" ? value : ""; // Default to an empty string for text fields
            } else if (field.type === "rating" || field.type === "percent") {
                value = typeof value === "number" ? value : null; // Default to null for numeric fields
            } else if (field.type === "multipleRecordLinks") {
                value = Array.isArray(value) ? value : []; // Default to an empty array for linked records
            }

            // Update the record with the duplicated value
            await table.updateRecordAsync(record.id, {
                [newName]: value,
            });
        }
    }
}

output.text("Fields duplicated successfully!");

 

1 Reply 1
Alexey_Gusev
13 - Mars
13 - Mars

Hi,
it has another type name

 

const table = base.getTable("Tasks");
const fieldId = await table.createFieldAsync("Notes", "multilineText");

 

Here you can find more info