Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
3 years ago

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