web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Workflow to Excel Scri...
Power Automate
Unanswered

Workflow to Excel Script, Fails to Retrieve Value Relative to Form Response

(0) ShareShare
ReportReport
Posted on by 8
Hello there,
 
I have a Microsoft Form that has a few questions on it, which also captures the email address of the submitter. I have an Excel file set up to capture the Form responses, and the responses come through just fine. These responses are duplicated on a separate worksheet that also contains other data relative to the responder, their email, and their responses.
 
As an example, the responses comes in on the sheet formResponses. These are copied over to a second worksheet called data, and there are extra columns after the responses, which use a VLOOKUP function to query a different sheet that contains employee info (ID, manager, manager email, location, etc.). That relative info is populated on data on the same row as the submitter's responses, and that all works just fine. There's no problem getting the info to show up correctly.
 
The problem I've been running into is trying to retrieve some of that relative data and sending it back to a Power Automate workflow, to use in a condition step. Here's the workflow I'm using:
 
-[Forms] When a new response is submitted
-Apply to each (List of response notifications)
  -Get response details (List of response notifications Response Id)
  -Run script
  -Condition (body/result > is equal to > OK
    -If True...
    -If False...
 
Here's the Excel script I'm using:
 
function main(workbook: ExcelScript.Workbook, email: string): string {
    var data = workbook.getWorksheet('data');
    var row = data.getRange("F:F").find(email, {completeMatch: true}).getRowIndex();
    var match = data.getRangeByIndexes(row, 10, 1, 1).getValue().toString();
    return match;
}
 
This workflow is passing the responder's email to the script, which looks at the data sheet, finds the row in which the email is listed, and pulls the value from the 11th column (index 10), returning it to the workflow to use in a true/false condition. Each time the form is filled out, I receive this error:
 
Action 'Run_script' failed: Bad Request Runtime error: Line 5: Cannot read properties of undefined (reading 'getRowIndex')
 
I've toyed with this a bit, and for my testing, I've used a field input on the Form as an email input, inputting a different fake email address each time, just to simulate unique submitters filling out the Form. So the workflow passes this fake email to the script, and the script is looking at the corresponding column to match it up. If I fill out the Form and use a fake email that's already on the sheet, there's no error at all. The script and workflow go through perfectly, condition rule is triggered correctly, and the corresponding action fires without issue. With that, my assumption is that the workflow and script are being triggered too quickly, before the responses are given time to populate on the Excel sheet.
 
To try and correct this, I've added a Delay step in the workflow before the 'Apply to each' step, trying increments up to 2 minutes, and yet this issue persists. I also tried inserting workbook.refreshAllDataConnections(); at the beginning of the script, in an attempt to force a refresh of the data (à la SpreadsheetApp.flush() from Google Apps Script), but that also did nothing to resolve the error.
 
I should also say that this workbook, where the responses are coming in, will not be open all the time while this Form is being used. This file will just exist out there on my drive while responses are being submitted through the Form.
 
Is there a way to force that refresh or otherwise wait until the Form responses are populated on the file so the script doesn't fail?
 
Thanks in advance, I'm just wading into the Power Automate / Excel script world after having spent many years in the Google Apps Script realm, trying to translate tools from one environment to the other.
I have the same question (0)
  • AndrianaO Profile Picture
    238 Moderator on at
    Hi! The fact that it's working fine for the existing email is a good sign, that means that the error is not in the script itself. And from the error message it does look like the record was not found, so trying to getRowlndex won't work on non-existing record.
     
    From your description of the flow I don't see any action that adds a row to the excel based on the form data. Do you have a separate flow that does that? How does an email appear in the excel file?
  • Josh_Actually Profile Picture
    8 on at
    Hi AndrianaO,
     
    Thanks for the response! The form itself is set up to receive responses, and the responses are fed directly via the form's own process. There's no extra step I take in power automate to add the response to the Excel file. On the Responses page on the form, it shows the Excel file in question, and the responses come in automatically. These responses come in on the formResponses sheet on the file.
     
    Let me know if you need any more info from me. Thanks!

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard