function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Set font bold to true for range 1:1 on selectedSheet
selectedSheet.getRange("1:1").getFormat().getFont().setBold(true);
// Add a new worksheet
let sheet1 = workbook.addWorksheet();
// Add a new pivot table on sheet1
let newPivotTable = workbook.addPivotTable("PivotTable1", selectedSheet.getRange("A1:G1000000"), sheet1.getRange("A3"));
// Rename worksheet to "PIVOT"
sheet1.setName("PIVOT");
// Add pivot field to a hierarchy in newPivotTable
newPivotTable.addRowHierarchy(newPivotTable.getHierarchy("COMMODITY DESC"));
// Add pivot field to a hierarchy in newPivotTable
newPivotTable.addRowHierarchy(newPivotTable.getHierarchy("DATE DT"));
// Add pivot field to a hierarchy in newPivotTable
newPivotTable.addRowHierarchy(newPivotTable.getHierarchy("ORIGIN LOC CD"));
// Add pivot field to a hierarchy in newPivotTable
newPivotTable.addRowHierarchy(newPivotTable.getHierarchy("COUNTRY CD"));
// Add pivot field to a hierarchy in newPivotTable
newPivotTable.addRowHierarchy(newPivotTable.getHierarchy("MONTH NM"));
// Add pivot field to a hierarchy in newPivotTable
newPivotTable.addColumnHierarchy(newPivotTable.getHierarchy("ROUTE NBR"));
// Change pivot position in a hierarchy in newPivotTable
newPivotTable.getColumnHierarchy("ROUTE NBR").setPosition(0);
// Add pivot field to a hierarchy in newPivotTable
newPivotTable.addDataHierarchy(newPivotTable.getHierarchy("AWB NBR"));
}
When I tried to run the script from the workflow, this is the error I see:

Report
All responses (
Answers (