Skip to main content

Notifications

Community site session details

Community site session details

Session Id : TqIgf7OUQrDHjesVyHrekr
Power Automate - Building Flows
Unanswered

Run Script error Line 9: tables.findAsync is not a function

Like (0) ShareShare
ReportReport
Posted on 16 Oct 2024 19:53:29 by
Good afternoon everyone! 
 
I have create an Office script in Excel to expand the columns and also add DataValidation. The script works fine in excel. But when I try to run it with Power Automate I get this error. Line 9: tables.findAsync is not a function. I'm not understanding the error as I don't have anything in the script that says findAsync. I would greatly Appreciate any help. Below is the script. Thanks in advance!
 
async function main(workbook: ExcelScript.Workbook) {
    // Get the active worksheet
    let sheet: ExcelScript.Worksheet = workbook.getActiveWorksheet("Sheet1");
 
    // Get all tables in the worksheet
    let tables: ExcelScript.Table[] = sheet.getTables();
 
    // Find the table named "Checklist"
    let table: ExcelScript.Table | undefined = tables.find(tbl => tbl.getName() === "Checklist");
 
    // If the table wasn't found, log an error and exit the script
    if (!table) {
        console.log("Error: Table 'Checklist' not found.");
        return;
    }
 
    // Get the range for Column C (Removed?) in the table
    let removedColumnRange: ExcelScript.Range = table.getColumnByName("Removed?").getRangeBetweenHeaderAndTotal();
 
    // Clear existing data validation (if any)
    removedColumnRange.getDataValidation().clear();
 
    // Define dropdown options as a comma-separated string
    const dropdownValues: string = "Yes,No";
 
    // Create validation rule
    const validationRule: ExcelScript.DataValidationRule = {
        inCellDropdown: true,
        list: {
            inCellDropdown: true, // Corrected the typo here
            source: dropdownValues
        }
    };
 
    // Set the validation rule
    removedColumnRange.getDataValidation().setRule(validationRule);
 
    // Auto-fit the columns in the table
    let tableColumns: ExcelScript.TableColumn[] = table.getColumns();
    tableColumns.forEach((column) => {
        column.getRange().getFormat().autofitColumns();
    });
}
  • ML-07021357-0 Profile Picture
    10 on 07 Feb 2025 at 15:01:54
    Run Script error Line 9: tables.findAsync is not a function
    I'm having a similar problem, but instead power automate goes in timeout. It seems the problem is the getDataValidation().setRule(validationRule) line, if I remove it the script works in Power Automate too, but I need it.
    Did you find a solution in the end?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
stampcoin Profile Picture

stampcoin 101

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 82 Super User 2025 Season 1

#3
David_MA Profile Picture

David_MA 48 Super User 2025 Season 1

Overall leaderboard
Loading started