web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Excel script give diff...
Power Automate
Unanswered

Excel script give different result through power automate.

(0) ShareShare
ReportReport
Posted on by 14

Hi,

I have a power automate that runs an excel script.

When I run the excel script through power automate it gives a different result then if I run it through manually.

BUT it is only happening opn 3 of the 46 sheets the codes run on.

 

Log output from the two versions is

Manually run

17/40 - Jupiter
cols: 8
rows: 54
(1) [Array(8)]
1 + insync
platinum
/rrp|trade|platinum|special/gim
2 + falseinsync
platinum
1 + insync
gold
/rrp|trade|platinum|special/gim
3 + 6

 

Power automate run

 

"[2022-12-05T03:39:37.5960Z] 21/45 - Jupiter",
"[2022-12-05T03:39:37.8930Z] cols: 8",
"[2022-12-05T03:39:37.8930Z] rows: 54",
"[2022-12-05T03:39:37.9550Z] [[\"Part code\",\"Short Description\",\"Description\",\"Warranty\",\"RRP \\n(Inc GST)\",\"TRADE \\n(Ex GST)\",\"InSync\\nGold\",\"InSync\\nPlatinum\"]]",
"[2022-12-05T03:39:37.9710Z] 1 + insync\nplatinum",
"[2022-12-05T03:39:37.9710Z] {}",
"[2022-12-05T03:39:37.9710Z] 3 + 7",
"[2022-12-05T03:39:38.0650Z] 1 + insync\ngold",
"[2022-12-05T03:39:38.0800Z] {}",
"[2022-12-05T03:39:38.0800Z] 3 + 6",

 

The difference is when i check the regex in power automate it doesnt find a match but when i run in excel directly it does find a match. (it is supposed to find a match)

this runs on over 40 worksheets and fails on 3-4 of them through PA.

 

Code is

 

 

function main(workbook: ExcelScript.Workbook, level: string) {

 

level = "plat"



let allsheets = workbook.getWorksheets()
level = level.toLowerCase()

 

const tradeKeyWords: string [] = [" rrp""trade"]
const platKeyWords : string[] = ["rrp""trade""platinum""special"]
const goldKeyWords: string[] = ["rrp""trade""gold""special"]

 

  let searchExp = new RegExp(tradeKeyWords.join("|"), "mgi")

 

if (level == "trade"){ searchExp = new RegExp(tradeKeyWords.join("|"),"mgi")}
if (level == "gold") { searchExp = new RegExp(goldKeyWords.join("|"), "mgi") }
if (level == "plat") { searchExp = new RegExp(platKeyWords.join("|"), "mgi") }

 

  for (let i = 17; i < allsheets.length ; i++){

 

//console.log(allsheets[i].getName())
 console.log( i + "/" + allsheets.length + "  -  "+ allsheets[i].getName())
    let headrow = allsheets[i].getUsedRange().find("Trade", { completeMatch: false, matchCase: false, searchDirection: ExcelScript.SearchDirection.forward }).getRowIndex()

 

  let numcols = allsheets[i].getUsedRange().getColumnCount();
  let numrows = allsheets[i].getUsedRange().getRowCount();
  console.log("cols: " + numcols)
  console.log("rows: " + numrows)



  let headvalues = allsheets[i].getRangeByIndexes(headrow,0,1,numcols).getValues()
  console.log(headvalues)

 

numcols = numcols -1

 

  let testValue = false
  testValue = headvalues[0][numcols].toString().toLowerCase().includes("trade")
  
    while( testValue === false ){

 

  console.log("1 + " + headvalues[0][numcols].toString().toLowerCase())
  console.log(searchExp)
       

 

  if (searchExp.test(headvalues[0][numcols].toString().toLowerCase()) == true){
    console.log("2 +   " + testValue + headvalues[0][numcols].toString().toLowerCase())
    }
    else{
      console.log("3 +   " + numcols)

 

      allsheets[i].getUsedRange().getColumn(numcols).delete(ExcelScript.DeleteShiftDirection.left)
    }

 

      numcols = numcols -1
      testValue = headvalues[0][numcols].toString().toLowerCase().includes("trade")
}
}
}

 

 

Categories:
I have the same question (0)

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard