How to remove items from array from Power Automate Flow

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello in this video i want to show you how you can remove an item from an array in poweradmit probably you know adding an item or appending an item to an array variable is easy there is just a built-in action uh that you can simply use it and add anything that you want to an array but how about removing an item there is no such an action that can do the job for you so it may not be as straightforward although it's very easy and in this video i want to show you how you can do that let's get into it let's have a quick review over our very simple setup i created a flow with a manual trigger and there are two arrays in it the simple one is the string array the other one is an object array which makes it a little bit more complicated but the basics are the same we just start with an easy example this is our setup inside our string array is just an array of a string so square bracket string a string b string c and string d and we want to find a way to delete one of them from this array variable which is a string array the other one obvious it's an array of objects so we have one object or one record as they say we have multiple of them and then we decide to pick one of them and delete it in the end there is a bonus and we talk about it when the time comes now why this becomes a little bit of question is because we have an action called append and you can easily append to an array so basically inserting or adding a record to an array and i'm pretty sure many of you have searched for something like delete and you expect to see delete something from an array which does not exist but how do we delete an item from an array in general delete from an array means we filter the array and we set the variable again to the filter result do you really think you need to watch the rest of the video well i don't think so but if you want to i'll be more than happy to present the rest of the video i start with initialize string array let's say we want to delete the record that the value is string c to do that i add a filter so right after this i say add an action and i pick up filter array there we go this filter array i want to rename it to exclude string c it should get its value from string array and i need to choose a value that i want to compare i would say string c this is my string c but i want to get rid of it i want to filter for everything that the value of this string is not equal to string c and i'm looking for the current item the item that the filter is working with is referred to as item under expression so if i say item open and closing the bracket it refers to the current record that is being processed and that's it i say ok so this filter should return everything that the item is not equal to string c so the filter part is complete then we need to put the filter result in the same variable that we filtered from that's it so i click on this guy add an action i say set variable i pick the set variable the variable that i want to set is the string array the value that i want to put inside this is going to be the output of this exclude string c filter so exclude the string c filter pick the body and we are set and to just revalidate the content of this string array i want to put it in a compose action i pick compose and inside this compose i want to put the string array let me just save it test test run done there we go in the beginning the string array cons contains a b c and d while now if i check the value in that it's going to be a b and d c is gone as simple as that we can delete an item from a string array let's take it to the next level i don't need the sky anymore and i can put this compose in the end so i can use it for object array so i don't need the string array anymore i put the object array inside it which nothing has been removed from it yet so let me just expand it for this one i want to delete someone whose first name is sarah so this is the record i'm looking for you can pick any other record but this is just my pick to do that we do exactly the same thing so just like before i add an action and i say filter array right there we go this time i say exclude sarah and i want to get it from object array just like before i'm looking for sarah is not equal to but this is not the current item this is a little bit further than that sarah is not the entire record whatever the item that we have we are looking for its first name which basically means if i come here i can again click on expression i can again refer to item but this time i say item dot first name don't look for suggestions the filter still doesn't have a clue what is inside that object to give you a suggestion of first name last name or whatever else that you have you have to just type it in and trust your typing skills i click on ok and just like before i click on add an action and i say set variable and i pick the set variable here the variable that i want to set this time is my object array and the value that i want to assign to it is the output from this filter excludes sarah so i click on this i find exclude sarah and i put body inside it did i reset compose yes i put the object array inside this compose let me just save it and test it again test test and run flow and i click on done now initialize object array contains everything including sarah jones and then when i go to the last compose you should not see sarah jones here anymore and she's gone now let's look at this one we have an array with the first name and the spouse now spouse has two properties of name and age the request is to delete a record with the spouse name scarlet basically we need to spot this record here i'm pretty sure you can do it yourself based on what you learned so far but you know what i love json and then let's do it i click on edit i add another variable i don't need these guys anymore i say initialize variable and i rename it to array with scarlett let me just copy the same name here and put it as a variable name type is array again and i already have typed this array somewhere else and i just paste it here so i have the entire array here i'm looking to filter for someone whose spouse name is scarlet then let's add our filter filter array let me just rename it i call it remove scarlet i picked item from array with scarlet again i'm looking for scarlet is not equal to and this time i'm looking for another expression i say item dot spouse dot name spouse dot name okay and next step is gonna be set variable okay this is my third set variable i say array with scarlet if i reassign the output from the remove scarlet now this array called arravid scarlett will be an array without scarlet let's test it save test test run flow done and there we go this is the variable without scarlet sarah is there alex is there cody is there but no scarlet all right it was short and easy i hope you enjoyed this video if you did you know where the like button is thank you for watching and i'll see you in the next video you
Info
Channel: Alireza Aliabadi
Views: 10,248
Rating: undefined out of 5
Keywords: how to remove items from power automate array, How to delete items from array in Power automate, How to delete items from Power automare array, delete flow array items, delete items from Power automare array, delete items from array variable, Power automate tips, power automate tutorial, flow array, flow string array, flow array of objects delete item, remove items from Power automate string array
Id: S6Vh3pQ7KIA
Channel Id: undefined
Length: 11min 13sec (673 seconds)
Published: Tue Aug 23 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.