Patch from Gallery to Datasource with Multiple Scenarios in Power Apps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is eric today we are going to look at pushing your records from a gallery to a data source now one of the most used controls in powerapps is a gallery and usually the gallery is supposed to store reports from your data source there are instances where you may want to push the record in the gallery to another or different data source or you may want to edit the record in the gallery and then updates the requisite have been updated in the data source and so there are several ways of achieving same with the patch you can use the update if function you can use the update function you can use the collect function but today we are going to focus on the patch function okay so we are going to look at patching directory from inside the data source inside that gallery we are going to patch from outside the guide that is placing the bottom that is not inside the gallery then we are going to look at how to push the records from a guy to a collection and then finally pushing them from the collection to the data source and we are also going to look at other scenarios including patching new records and then updating records so it's supposed to be an exciting tutorial thank you very much and let's get straight to action [Music] okay so this is my gallery with four items as you can see here there are four rules so when i scroll down i have four items in my data source now my data source this is my data source the name my first list has the items id first name amount title and other columns now this is connected to this guy and so this is exactly what we are going to use for the virus example but before then let's look at the patch function when we look at the patch function um you can see that you use pipe to modify records in corporate situations so basically the patch function is used to modify record as well as create new record and to create new record we use the as default is stipulated here okay so let's go back to the power-ups and see how these things goes okay so when we look at the gallery and look at this screen i have some check boxes and then i also have a toggle control now if you want to patch a particular item so for example want to patch xiao 1000 12001 the first record we want to modify and then patch it back to the data source when we look at the first record we have we have amount 12 000 and the other ones continues so we want to change you how to say kojo and then we are changing the 12 000 to say 13 000. now if you want to update this new record back to the data source and uncheck of this checkbox i have a formula here so this is what we are going to do we are going to use the patch function and then the patch function is taking the data source and then a record that you want to update and we are updating this particular item which is in the guide this item then we are updating two columns we are updating the first name and then we are updating the amount now the first name is in the first name text box and then the amount is on the amount textbook so when we look at the unknown check you see that the first name matches to the first name text box dot text and then the amount we have rapid value because it is a number or a currency column so with this new changes when we click on the check box and we take the check box you see that dot dot dot moving and then you see that the record has really changed from yao to kojo so when we look at the loop back it is still here and then 12 000 and then let's refresh the data source after refresh letter so we see that kojo test change and amount has slowly changed from 12 000 to thirteen thousand so that is the first example of patching directly from inside the diary back to your data source so what it means is that whenever you check any of these check box the changes that have been done inside the gallery will be recorded back to your data source for it to update the old record to capture the new record so that is the first example the second example what if you want to check this checkbox and then whatever is here is repeated or is created as a new record inside data source so for instance i change this one to mansa musa and i change this to ten thousand and i want to create this as a new record in my description when we look at a data source i have one two three four items and i want to create the fifth item by changing the old record that was here to the new record so in that case we are going to use the defaults as we saw as part of the centers of the patch function okay so when we go to the uncheck the old formula that we are having there is this item so we have to change these items to defaults defaults and then we bring back the default has to take the name of the data source so default the name of the data source which is my first and that is it now if you want to push this to another data source it's a matter of changing the name of this data source and then placing the name of the new data source there so when we click this you see the dot dot you see that it changes from four to five it means that we now have a new record that has been added so we can check from the sharepoint list and now you see here we have another record being added man service at 10 000. so that is the second example that we have looked at so we have looked at so in our next scenario we are looking at patching from your gallery to a data source on the bottom that is not located inside your gallery so we have placed the bottom that is outside the gallery on our screen but we want to patch whichever item is selected in the gallery from this button into the data source so in that case you will have to one of the tricks that you need to know is that there should be an id column so on your data source so in this disciples i have this id one two three so if you are using an s as a data source you may have a column that is unique name necessary one two three but it should be a unique identifier same applies to sql server or whatever data source you are using in my case i am using a sharepoint list so we i have this formula patch then i have my data source then after that the record to updates i'm looking at a particular id so patch loop we are looking look up id is equals to value that is in id test input box now and look at the test input box i have this item dot id one and then i have to try as it is in my data source so whatever item is selected from the gallery go back to the data source compare the id in this selected item if it's equal to the id in the data source go back and change it that is the formula lookup first item id in the data source if it is equal to the value in this test input box then go back and then make these changes to these columns and the columns that i have stated are amounts and then first name so let's see how it goes i will make a change to so i have here i'm going to type dennis dennis and then i'm changing the record from 5000 to 65 0 650 so i'm saying that go back to the data source if you identify a column with an id of 3 make the change to dennis and then change the amount to 650 so i click on the bottom you see the dots working then after that i will go back to the data source and see if the id column 3 has really made the very various changes that i have done i think i have a slow internet okay so when we go back to the data source and uh we see that the road trail with id column tray has really changed to dennis and the amount has also changed to cis 650 okay so now we'll move to another scenario okay so in our next scenario we are looking at making changes to multiple records in the gallery and i'm pushing same back to the data source so in all the examples that i've given earlier we're making records to a particular row but now what if you want to make changes to different records or rows in the gallery and then you want to push all of them back to the data source so for instance i make a change to id1 i change it from kodo to elizabeth i change the amount to say 65 20. then instead of joist m i make it joist done and also change this one to from 20 to 12. and then i want to make changes to the data source for these two records that i've made in that case this is the formula that i'm using on patch i'm using for all function and then for the for function i am renaming the id column what is inside the gallery there are 1.4 items and the new name i'm giving it is new id so another controller i have here is a checkbox now the purpose of the checkbox to ensure that although i have made so many changes in the gallery i want to ensure that there is not inadvertent sending of data or changing of data so the user need to really click on this icon to ensure that these checked icons or these ticked records and the one that i want to patch to the data source so in the formula i am checking if checkbox1 dot value that is if checkbox one has really been checked then go ahead and look up comparing that the id in the data source is equal to the new item then when these two conditions are met go ahead and patch so i should go through again for every record for all in the gallery rename all the columns with id to new id after that check if the check box inside the gallery has been ticked or when the checkbox is really true then after that compare the id in the data source if the id is equal to the new id that is the rename id then go ahead and patch these columns the amount and the first name and you can go ahead and then make various changes so for this example i have checked this so let's let me change they need to say do it so i change this genus to dual and i'm making 657 now although i have made changes to three items one two three i am not checking the jewel meaning that the jewel shouldn't be sent back to the data source so i go ahead and click on the button and we'll go back to the data source let's refresh so we see elizabeth has changed joy's done has changed dennis is still dennis although i changed it to do it so that is it now the advantage of renaming the column and also placing the check box inside the gallery is that for all is actually has a very tool on your on your performance of the app so if you are using the forum function inside the app make sure you have a way of limiting the number of rows that's to go through so if you don't need to go through all the columns or the rules in the gallery then placing the checkbox will help you improve the performance so only when those checkbooks are ticked that's the record will be changed using this for all and the patch function thank you so we are moving to our next example our next scenario so in our next scenario we are first of all pushing the record from the gallery into a collection and having finished pushing every record that we want to update into your collection we will patch from the collection into a better source in fact this is the most efficient way of going about this patching as far as this guy is concerned so first of all i have placed a checkbox and on check of this checkbox i am collecting the amount and the name column that is why we are making changes you can increase or you can add more into a collection called call my items and then from that i am picking the id and i'm also picking the amount and picking the first name so for every record so let's go back to our collection and check you see that currently i have some items already in the collection so let me remove them let me remove them and then create new items so let me go back okay so when you go back to the collection you see that there's nothing in the collection okay so we go back and then we start updating i update elizabeth to frank change the amount to 80 then i take this checkbox now when i take this checkbox the record that has been changed is pushed into the data source so let me go down and change my submission to johnson and then change this to three or 30 then i collect i'll go back and change another record to hike and i will leave this and i collect it so now i have three items selected now let's go back to the collection and check whatever is there my call okay so we see sorry the collection my internet is ruggish so here is the collection the three items that i selected is displayed in the collection now from there let's look at the patch formula just like we said earlier we are renaming the column with the id to a new id then from there we are patching into my first and then before we patch we are looking up into the data source and then comparing the id the data source with the new id inside the collection when being matched we go ahead and patch for each of the record that is listed into the collection back into the data source so let's create let's see how this thing goes okay so we go back into and check we change elizabeth to like exchange and then we see that the various changes have been made okay so let's you look at the same patch using the disambiguation now in our first or in an earlier patch we use the we rename the column id into a new column if you don't want to go by this you can use the disambiguation to differentiate between the id in the collection and the id in the data source so in that case for all the collection patch into my first data source but however look up into the data source if the id is equal to the collection dot id but we are not because we didn't rename we are using the disambiguation that is at id inside the formula so this query doesn't give any error and it goes back and then works the same as renaming of the id column into another article thank you very much go ahead and look at our final scenario now in our final scenario we are also going to push the data from the guy to a collection then we push the collection to the data source so in this case we are going to follow the previous example we will look at we have a collection micro which is currently empty it doesn't contain any record now on on check of this checkbox we have the same formula that we used previously then on uncheck we because we want to remove the item i also have remove correction this item so whenever you untick it the item is removed from the record or from the collection so we make a change to done so than 2 i change this to 1 30 then i check it and go back to your menu and make it yeah and i'm changing from 120 to 123 i take it so when we go back to the data source or the collection let's check the collection so we have the two here help drives to yao juju very defined here with the various id columns now instead of using the previous formula that we use we are using a very simple and straightforward patch function and we are patching to the data source right away from the collection and this supposed to be a very good and straightforward way of patching from your collection back to your data source now the cache here is that ensure that you have an id column that is unique in your data source which has also been pushed into the collection and that i said earlier so let's go back and patch and see how it goes so we are changing to records we go back to our data source let's refresh it and we see that we have joyce ii and then we have yao jojo clary changed so this is the end of the tutorial i hope you enjoyed it and i hope you go ahead and subscribe i'll be doing a second version of this using either collection and an update if thank you very much you
Info
Channel: Eric Entsie
Views: 7,130
Rating: undefined out of 5
Keywords:
Id: gKWf_XQyIH0
Channel Id: undefined
Length: 27min 7sec (1627 seconds)
Published: Sun Apr 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.