Forum Discussion
Script works online but not in Power Automate
I have a script it works online but when I add it to a power automate flow it is pulling in wrong data. I basically have an employee file with status. I want to filter off our various termed employees onto a separate sheet. Once it is ran through Power Automate essentially every employee is moved to the term list. We have roughly 10,000 employees and only a dozen or so people remain on the report. Any suggestions.
function main(workbook: ExcelScript.Workbook) {
const table = workbook.getTable("Table1");
const EmployeeStatusColumn = table.getColumnByName("Employee Status");
EmployeeStatusColumn.getFilter().applyValuesFilter(["Terminated","Backout","Fall off","Terminated w/Severance"]);
workbook.addWorksheet().getRange().copyFrom(table.getRange());
let sh: ExcelScript.Worksheet = workbook.getWorksheet("Report")
let visibleRows = table.getRangeBetweenHeaderAndTotal().getVisibleView().getRows()
let firstVisibleRow = visibleRows[0].getRange().getRowIndex() + 1
let lastVisibleRow = visibleRows[visibleRows.length - 1].getRange().getRowIndex() + 1
sh.getRange(`${firstVisibleRow}:${lastVisibleRow}`).delete(ExcelScript.DeleteShiftDirection.up)
table.getColumnByName("Employee Status")
.getFilter()
.clear();
}
1 Reply
- v-yalanwu-msftCommunity Support
Hi, Syndicate_Admin ;
From your code found that there are filters, perhaps because the filter caused the data from 10,000 to a dozen employees, you try to remove the filter to check if this is the reason, if so, change the filter.
Run Office Scripts with Power Automate - Office Scripts | Microsoft Learn
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.