How to sort an array of objects with Power Automate

preview_player
Показать описание
How to sort an array of objects with Power Automate by harnessing Office Scripts in a simple two step flow, using Office Scripts. Full details at:
Рекомендации по теме
Комментарии
Автор

Ok, to everyone who is looking at the solution for their flow not working and you getting errors either in Excel online and/or PA.
It doesn't matter the script gives you errors in excel online, the flow is going to work.
I was getting data through custom connector from the web and then taking data using Select. In the field strArray in Run script I was taking data from said Select. If this is your case, just use Compose instead.

NOT: select > Run script
DO: Select > Compose > Run script

maixnerx
Автор

Thats amazing..as i said before your videos are packaged with full of knowledge..thanks again

arshad
Автор

Amazing video! I'll add that this works with variables. If you are using a variable, in strArray you can replace string(outputs('array')) with and it should work

MrBlastCorp
Автор

Its a neat solution and will be very usefuly, if I am able to sort out a small issue with the script itself.
It throws an error in the xl code edditor which goes like this : Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.
I think its to do with the line : let array = JSON.parse(strArray);
I don't have any prior knowlwdge of typescript and hence any suggestions or help will be appreciated

DA_CSF
Автор

Hi everyone, I ran with the same issues with the script, the issue on my side was that I was trying to get the individual values of the result from the script to populate a word template, and apparently that cannot be done, after three days trying to find out what was the issue, I tried to set a variable with the script results and them get the individual results from there, and it works!!!..hoping this work for you guys.

Автор

Hi Thank you so much for this.
I cant seem to find the Automate tab on my excel online. My admin did confirm that the Office script is enabled. Help?

joelgeorgeejoseph
Автор

Does this still work? I used your playerRankings array today and input it as a stringArray but it still gives an error saying it requires the property 'body/result' to be of type String but it is of type Array. Any help would be appreciated 🙂

dinnerkill
Автор

Hello Paulie,
First of all thanks for the amazing scrip. Works as a charm.
Can this script be used to sort by three properties at the same time (so in your example first by for example Ranking, than Age and then Points (for example).

Thanks and regards,
Marcin

marcinpazdro
Автор

Hi Paulie. Something seems to have changed since you recorded your video and now the script shows an error as at 20th March 2022.
On pasting the code into the script editor, the "array" variable declared after "let" is shown with the dreaded red squiggly intellisense error line underneath, with a message "office scripts cannot infer the data type of this variable. please declare a type for the variable". I have searched quite a bit online but haven't found an intuitive way to fix this. It would be great if you could suggest if/how this could be fixed.

josephansah
Автор

That’s great, didn’t know you could run an office script like that in Power Automate! Any idea how you could write a script to detect if duplicate entries exist in an array?

robofski
Автор

Sir, That's a wonderful solution.
But we are facing a problem while running the script.
Its not Sorting my array in the proper way I want.
Can you please guide me how can I solve this error.

prabhalgarg