Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

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

(1) ShareShare
ReportReport
Posted on 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();
    });
}
  • Suggested answer
    Community member Profile Picture
    2 on at
    Run Script error Line 9: tables.findAsync is not a function
    Hello all,
     
    I had the same problem and found in Stack Overflow a solution that worked. As a matter of fact, it seems that Power Automate runs into problem when handling the JavaScript find() function. To address this I used a for() loop and the script run perfectly through Power Automate.
     
    I hope this helped,
    Christos
  • ML-07021357-0 Profile Picture
    10 on at
    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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 566 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 516 Super User 2025 Season 1

#3
stampcoin Profile Picture

stampcoin 492