cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Piter_D
Responsive Resident
Responsive Resident

Problem with running excel script in flow

Hey, I created a flow where I want to export data from my database in sharepoint to excel. If I start the flow, there is no problem, but when someone else wants to start them, he gets badrequest 502 in the application and in flow there is information that the script is not shared or has been removed.

Piter_D_0-1646225830436.png

and this is script:

function main(workbook: ExcelScript.Workbook, csv: string) {
  let sheet = workbook.getWorksheet("Sheet1");

  /* Convert the CSV data into a 2D array. */
  // Trim the trailing new line.
  csv = csv.trim();

  // Split each line into a row.
  let rows = csv.split("\r\n");
  // Split each line into a row.
  if (csv.search(/\r\n/) > - 1) {
    rows = csv.split("\r\n");
  } else if (csv.search(/\n/) > - 1) {
    rows = csv.split("\n");
  } else if (csv.search(/\r/) > - 1) {
    rows = csv.split("\r");
  }
  rows.forEach((value, index) => {
    /*
     * For each row, match the comma-separated sections.
     * For more information on how to use regular expressions to parse CSV files,
     * see this Stack Overflow post: https://stackoverflow.com/a/48806378/9227753
     */
    let row = value.match(/(?:,|\n|^)("(?:(?:"")*[^"]*)*"|[^",\n]*|(?:\n|$))/g);

    // Remove the preceding comma.
    row.forEach((cell, index) => {
      row[index] = cell.indexOf(",") === 0 ? cell.substr(1) : cell;
    });

    // Create a 2D-array with one row.
    let data: string[][] = [];
    data.push(row);

    // Put the data in the worksheet.
    let range = sheet.getRangeByIndexes(index, 0, 1, data[0].length);
    range.setValues(data);
  });

  // Add any formatting or table creation that you want.
  let newTable = workbook.addTable(sheet.getUsedRange(), true);

  // Set number format for range H:H on sheet
  sheet.getRange("A:A").setNumberFormatLocal("@");
  // Set number format for range H:H on sheet
  sheet.getRange("B:B").setNumberFormatLocal("@");

  // Sort on table: newTable column index: '6'
  newTable.getSort().apply([{ key: 6, ascending: true }]);
}
1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @Piter_D ,

 

Unfortunately, executing script can only use the script owner's connection.

Please take a look at this.

https://powerusers.microsoft.com/t5/Building-Flows/Office-Script-Error-quot-Script-not-found-It-may-...

You could find solution in this post.

 

Best Regards,

Wearsky

View solution in original post

2 REPLIES 2
Piter_D
Responsive Resident
Responsive Resident

and the strange thing is that flow despite the failure to excel file is still created

v-xiaochen-msft
Community Support
Community Support

Hi @Piter_D ,

 

Unfortunately, executing script can only use the script owner's connection.

Please take a look at this.

https://powerusers.microsoft.com/t5/Building-Flows/Office-Script-Error-quot-Script-not-found-It-may-...

You could find solution in this post.

 

Best Regards,

Wearsky

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,493)