Skip to main content

Notifications

Community site session details

Community site session details

Session Id : YpPegqzapQdlhMwqTgGy+L
Power Automate - General Discussion
Unanswered

Excel Script ran by Automate had different result from direct run

Like (0) ShareShare
ReportReport
Posted on 17 Oct 2023 07:30:07 by 4

Hello,

I have a strange issue.

When I run my excel script with office online or excel desktop, the logging result looks fine. However, when I use Automate to trigger it, the return result was wrong. 

 

 

function main(workbook: ExcelScript.Workbook) {
 // Get the active worksheet
 let sheet = workbook.getWorksheets()[0];
 let rowCount = sheet.getUsedRange().getRowCount();
 let objList: { [key: string]: string }[] = [];
 for (let row = 2; row < rowCount; row++) {
 let tempObj = {
 columna: "",
 columnb: "",
 columnc: "",
 columnd: "",
 columne: "",
 columnf: "",
 columng: "",
 columnh: "",
 columni: "",
 columnj: "",
 columnk: "",
 columnl: sheet.getCell(row, 11).getText().toString(),
 columnm: "",
 columnn: sheet.getCell(row, 13).getText().toString(),
 columno: sheet.getCell(row, 14).getText().toString(),
 columnp: "",
 columnq: "",
 columnr: "",
 columns: "",
 columnt: "",
 columnu: "",
 columnv: sheet.getCell(row, 21).getText().toString(),
 columnw: "",
 columnx: sheet.getCell(row, 23).getText().toString(),
 columny: "",
 columnz: ""
 };
 objList.push(tempObj);
 }

 // Convert the object to a JSON string
 let json = JSON.stringify(objList);
 json = json.replace(new RegExp('columna', 'g'), 'Airline Carrier')
 json = json.replace(new RegExp('columnb', 'g'), 'Flight Number')
 json = json.replace(new RegExp('columnc', 'g'), 'AWB #')
 json = json.replace(new RegExp('columnd', 'g'), 'Origin Pickup City')
 json = json.replace(new RegExp('columne', 'g'), 'Destination Delivery City')
 json = json.replace(new RegExp('columnf', 'g'), 'Shipper Name')
 json = json.replace(new RegExp('columng', 'g'), 'Origin Terminal Name')
 json = json.replace(new RegExp('columnh', 'g'), 'Loading Port Name')
 json = json.replace(new RegExp('columni', 'g'), 'Discharge Port Name')
 json = json.replace(new RegExp('columnj', 'g'), 'Destination Terminal Name')
 json = json.replace(new RegExp('columnk', 'g'), 'Actual Pick-up Arrival Date')
 json = json.replace(new RegExp('columnl', 'g'), 'Actual Delivery Arrival Date')
 json = json.replace(new RegExp('columnm', 'g'), 'Original Port ETD Date')
 json = json.replace(new RegExp('columnn', 'g'), 'Actual Port Arrival Date')
 json = json.replace(new RegExp('columno', 'g'), 'Actual Port Departure Date')
 json = json.replace(new RegExp('columnp', 'g'), 'Destination Terminal Arrival Date')
 json = json.replace(new RegExp('columnq', 'g'), 'Customer Reference Number')
 json = json.replace(new RegExp('columnr', 'g'), 'BOL')
 json = json.replace(new RegExp('columns', 'g'), 'Actual Quantity')
 json = json.replace(new RegExp('columnt', 'g'), 'Actual Weight')
 json = json.replace(new RegExp('columnu', 'g'), 'Volume')
 json = json.replace(new RegExp('columnv', 'g'), 'CHR Status')
 json = json.replace(new RegExp('columnw', 'g'), 'Customer Name')
 json = json.replace(new RegExp('columnx', 'g'), 'CHR Number')
 json = json.replace(new RegExp('columny', 'g'), 'House B/L Number')
 json = json.replace(new RegExp('columnz', 'g'), 'Dimensional Weight')

 // Log the JSON string
 console.log(json)
 return json
}

 

 

And this is my table content

Truman_0-1697527386015.png

It should return value:

 

 

[
 {
 "Airline Carrier": "",
 "Flight Number": "",
 "AWB #": "",
 "Origin Pickup City": "",
 "Destination Delivery City": "",
 "Shipper Name": "",
 "Origin Terminal Name": "",
 "Loading Port Name": "",
 "Discharge Port Name": "",
 "Destination Terminal Name": "",
 "Actual Pick-up Arrival Date": "",
 "Actual Delivery Arrival Date": "Actual Delivery Arrival Date",
 "Original Port ETD Date": "",
 "Actual Port Arrival Date": "Actual Port Arrival Date",
 "Actual Port Departure Date": "Actual Port Departure Date",
 "Destination Terminal Arrival Date": "",
 "Customer Reference Number": "",
 "BOL": "",
 "Actual Quantity": "",
 "Actual Weight": "",
 "Volume": "",
 "CHR Status": "CHR Status",
 "Customer Name": "",
 "CHR Number": "CHR Number",
 "House B/L Number": "",
 "Dimensional Weight": ""
 },
 {
 "Airline Carrier": "",
 "Flight Number": "",
 "AWB #": "",
 "Origin Pickup City": "",
 "Destination Delivery City": "",
 "Shipper Name": "",
 "Origin Terminal Name": "",
 "Loading Port Name": "",
 "Discharge Port Name": "",
 "Destination Terminal Name": "",
 "Actual Pick-up Arrival Date": "",
 "Actual Delivery Arrival Date": "actual Delivery Arrival Date 2",
 "Original Port ETD Date": "",
 "Actual Port Arrival Date": "Actual Port Arrival Date2",
 "Actual Port Departure Date": "actual Port Departure Date2",
 "Destination Terminal Arrival Date": "",
 "Customer Reference Number": "",
 "BOL": "",
 "Actual Quantity": "",
 "Actual Weight": "",
 "Volume": "",
 "CHR Status": "CHR Status2",
 "Customer Name": "",
 "CHR Number": "CHR Number2",
 "House B/L Number": "",
 "Dimensional Weight": ""
 }
]

 

 

But when I use Automate it was:

 

 

[
 {
 "Airline Carrier": "",
 "Flight Number": "",
 "AWB #": "",
 "Origin Pickup City": "",
 "Destination Delivery City": "",
 "Shipper Name": "",
 "Origin Terminal Name": "",
 "Loading Port Name": "",
 "Discharge Port Name": "",
 "Destination Terminal Name": "",
 "Actual Pick-up Arrival Date": "",
 "Actual Delivery Arrival Date": "CHR Number",
 "Original Port ETD Date": "",
 "Actual Port Arrival Date": "CHR Number",
 "Actual Port Departure Date": "CHR Number",
 "Destination Terminal Arrival Date": "",
 "Customer Reference Number": "",
 "BOL": "",
 "Actual Quantity": "",
 "Actual Weight": "",
 "Volume": "",
 "CHR Status": "CHR Number",
 "Customer Name": "",
 "CHR Number": "CHR Number",
 "House B/L Number": "",
 "Dimensional Weight": ""
 },
 {
 "Airline Carrier": "",
 "Flight Number": "",
 "AWB #": "",
 "Origin Pickup City": "",
 "Destination Delivery City": "",
 "Shipper Name": "",
 "Origin Terminal Name": "",
 "Loading Port Name": "",
 "Discharge Port Name": "",
 "Destination Terminal Name": "",
 "Actual Pick-up Arrival Date": "",
 "Actual Delivery Arrival Date": "CHR Number2",
 "Original Port ETD Date": "",
 "Actual Port Arrival Date": "CHR Number2",
 "Actual Port Departure Date": "CHR Number2",
 "Destination Terminal Arrival Date": "",
 "Customer Reference Number": "",
 "BOL": "",
 "Actual Quantity": "",
 "Actual Weight": "",
 "Volume": "",
 "CHR Status": "CHR Number2",
 "Customer Name": "",
 "CHR Number": "CHR Number2",
 "House B/L Number": "",
 "Dimensional Weight": ""
 }
]

 

 

The automate workflow has no problem, I just simply trigger it to run certain file.

Truman_0-1697527682140.png

 

  • CFernandes Profile Picture
    8,283 Most Valuable Professional on 17 Oct 2023 at 09:12:29
    Re: Excel Script ran by Automate had different result from direct run

    @Truman - Save the Script with a different unique name, select the new script and try to run it... Use the path and select the document manually. 

  • Truman Profile Picture
    4 on 17 Oct 2023 at 08:21:56
    Re: Excel Script ran by Automate had different result from direct run

    I also thought of that, my automate use file path to run the script at first, then I change to passing fileID.

    Both way return wrong result.

  • CFernandes Profile Picture
    8,283 Most Valuable Professional on 17 Oct 2023 at 08:09:36
    Re: Excel Script ran by Automate had different result from direct run

    Hey   

    I see that you are passing "id" manually select the file and run it. "Power Automate has some limitation a for the dynamic selection of workbooks"

     

     

    https://learn.microsoft.com/en-us/office/dev/scripts/testing/power-automate-troubleshooting#select-workbooks-with-the-file-browser-control 

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

     

    P.S. take a look at my blog here and like & subscribe to my YouTube Channel thanks.

     

    CFernandes_0-1697530157551.png

    @Truman

  • Truman Profile Picture
    4 on 17 Oct 2023 at 07:54:00
    Re: Excel Script ran by Automate had different result from direct run

    The first correct result I paste was the result when I ran the script manually with excel online or desktop. But Automate result was wrong.

     
  • CFernandes Profile Picture
    8,283 Most Valuable Professional on 17 Oct 2023 at 07:50:45
    Re: Excel Script ran by Automate had different result from direct run

    Hey @Truman 

     

    In the run script action if you manually select the path can you check if it gives correct result...

    CFernandes_0-1697528929076.png

     

     

    If you run the script in the Excel Online on the Excel file do you get correct results?

     

    CFernandes_2-1697529036714.png

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

     

    P.S. take a look at my blog here and like & subscribe to my YouTube Channel 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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,089 Most Valuable Professional

Leaderboard