cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dheeraj867
Helper IV
Helper IV

any substitute for for each loop in desktop flow

like i want to substitute the for each loop because it taking time any substitite for that

14 REPLIES 14
MichaelAnnis
Super User
Super User

You can just do a loop, so you can dictate the beginning and end. 

for example, if I had a spreadsheet and it had 1000 rows, but I only want to process row 2-100.

 

Launch Excel

Set variable %LoopMax% to 100

Loop starting at 2 to %LoopMax% interval of 1

’Now %LoopIndex% will always be the row I am on

 

Same goes with Files:

 

Get Files

Loop 0 to 99 increment of 1

‘ The current file is always %Files[LoopIndex]%

can we use java script for this to run more faster what u think?

Highboy
Super User
Super User

Just did a test, by reading a spreadsheet with 1000 rows.
Did a loop using FOR EACH and a normal LOOP, in those two loops I converted each row to numbers.
Both loop's took exactly 47 seconds (running from within PAD)

can u try this with Run Java Script

Could you be more specific?
My knowdledge about Java is limited.....😊

like we applying loop in drag and drop can we do this manually in java scripts i think it will do more faster i never tried but i need suggestion and implementation and my knowledge in js is very limited😅

Hmmm then you would have to do all your scripting in Java - I think.
What are you trying to do inside the loop?

nope i just finding alternative of for each loop

Can't see what's wrong with using Loop or For each, it's more likely what you are doing inside your loop that slows you down.

like if i have 10000 records it will take more and more time for reducing time that why i need a suggestion that if we apply same in java script then what will happen

Well I don't know what you are doing to your records in your loop, but we handle excel sheets with more than 20.000+ rows where each row has to be taken care of, and it does not take that long, when it runs unattended on our servers.

 

But I wish you all the best in your search, and please let me know if you find another way to do it - always eager to learn.

VJR
Super User
Super User

Hi @dheeraj867 

 

Can you elaborate the complete requirements what are you trying to achieve using javascript and loops, in which application (Excel?), and what exactly in that application?

 

Power Automate 22-02-2022 23_05_46.png

Power Automate 22-02-2022 23_05_54.png

Power Automate 22-02-2022 23_06_01.png

  i want to optimize this using java script

VJR
Super User
Super User

Loop using javascript for interacting with Excel.

  

Make sure to change Excel path and remember to give double slash \\ as shown below.

 

Customise as per you requirements.

 

Javascript-

  

var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("C:\\test\\LoopExcelJavascript.xlsx");
excel.visible = true;
var excel_sheet = excel.Worksheets("Sheet1");
var data="";
var col=1;
var i;

for (i=2; i<=6;i++)
{
 data = excel_sheet.Cells(i,1).Value;
data = data.substring(3);
 excel_sheet.Cells(i,1).Value = data;
WScript.Echo(data);
}

excel_file.save;
excel_file.close;

 

VJR_1-1646797808245.png

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022- Season 2 has kicked off!

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