In the previous 3 blog parts, we have shown what data source we are using, Data Model View, how to connect to any data source in Power Apps, how to read data from any Data source, how to create records using the Patch method for column of any data type to perform CRUD Operations.
In this blog, we will be showing:
Create a new button, UPDATE Button, and on its OnSelect Property, add this code mentioned a few lines below. Here, I would like the reader to Compare this below piece of code with the Compiled Save Code.
Create a new button in the screen “scr_Add/Edit” and rename it to “btn_Update” .
Copy-Paste the below code in the “btn_Update”
//------------------ Logged In User (mail, displayName) --------------------------- Set(gv_loggedInUserEmail,Office365Users.MyProfileV2().userPrincipalName); //storing Email of the user in this variable. Set(gv_loggedInUserDisplayName,Office365Users.MyProfileV2().displayName); //storing DisplayName of the user in this variable. ForAll( SortByColumns('cmb_LikesToPlayWhichGames?'.SelectedItems,"Sport"), Collect( col_SelectedGames, { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Id: ThisRecord.ID, Value: ThisRecord.Name } ) );//we are making this collection to save the "Like To Play Which Games?" combo box of LookUp type. And, first we pass this collection in Patch code below and then we are clearing this collection at the end of this code. If( var_IsNewRecord= true, Patch( list_PatchingFromPowerApps, { Name: txtInp_Name.Text, //single line of text Age: Value(txtInp_Age.Text), //number Description: txtInp_Description.Text, //multiple lines of text IsPass: If(radio_IsPass.Selected.Value = "Yes" , true, false), //boolean 'Date of Birth':datepkr_DateOfBirth.SelectedDate, //date Teacher: { Claims: "i:0#.f|membership|" & Lower(gv_loggedInUserEmail), Department: "", DisplayName: gv_loggedInUserDisplayName, Email: gv_loggedInUserEmail, JobTitle: "", Picture: "" }, //person type column Grade: dd_Grade.Selected, //Choice column (dropdown/radiobtn) 'Favourite Book Genre':cmb_FavouriteBookGenre.SelectedItems, //Choice column (checkbox multiselect) 'Favourite Subject': { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Id: dd_Subject.Selected.ID, Value: dd_Subject.Selected.Name },//Lookup column from a different list from same SharePoint Site. Can hold single value. 'Likes To PLay Which Games?':col_SelectedGames, //Lookup column from same SharePoint Site. Can hold multiple values. Fees:Value(txtInp_Fees.Text), //Currency 'Favourite Website':txtInp_FavouriteWebsite.Text //HyperLink } ), Patch( list_PatchingFromPowerApps, LookUp( list_PatchingFromPowerApps, ID = gal_ViewOnlyRecords.Selected.ID ), { Name: txtInp_Name.Text, //single line of text Age: Value(txtInp_Age.Text), //number Description: txtInp_Description.Text, //multiple lines of text IsPass: If(radio_IsPass.Selected.Value = "Yes" , true, false), //boolean 'Date of Birth':datepkr_DateOfBirth.SelectedDate, //date Teacher: { Claims: "i:0#.f|membership|" & Lower(gv_loggedInUserEmail), Department: "", DisplayName: gv_loggedInUserDisplayName, Email: gv_loggedInUserEmail, JobTitle: "", Picture: "" }, //person type column Grade: dd_Grade.Selected, //Choice column (dropdown/radiobtn) 'Favourite Book Genre':cmb_FavouriteBookGenre.SelectedItems, //Choice column (checkbox multiselect) 'Favourite Subject': { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Id: dd_Subject.Selected.ID, Value: dd_Subject.Selected.Name },//Lookup column from a different list from same SharePoint Site. Can hold single value. 'Likes To PLay Which Games?':col_SelectedGames, //Lookup column from same SharePoint Site. Can hold multiple values. Fees:Value(txtInp_Fees.Text), //Currency 'Favourite Website':txtInp_FavouriteWebsite.Text //HyperLink } ) ); Clear(col_SelectedGames); Navigate(scr_View); /* If( Creating New Record, Do as shown in the Save Code, LookUp the existing record on Primary Key, here "ID" which is managed by SharePoint and UPDATE (same syntax as Save Code) that Record. ) */
Explanation of the UPDATE code:
When we are Editing a record, that means on the On-Select Event of the Record in “scr_View”, firstly we are setting the value of the Variable “var_IsNewRecord” to false, and then we are navigated to the “scr_Add/Edit”.
Let us take an example. Suppose we want to Edit the first record as shown in the image below.
Now, press Update button on this screen.
On pressing Update button, the following things happens:
Same explanation through code:
Remove(list_PatchingFromPowerApps, ThisItem) //Deleting this record from the DataSource that is “list_PatchingFromPowerApps”.
In this blog we learnt how to Update and Delete the records of any data source using Power Apps as a part of CRUD operations.
Firstly, at the time of updating/editing what all things should be kept in mind i.e., setting up the screens(regarding the event of navigating to and from View screen and Edit Screen, we must reset the controls appropriately, whether to be prefilled with existing values at the time of editing and to be reset to blank at the time of navigating back to View Screen).
Secondly, we learnt how to write the Update code to update the records and asked the learner to compare the piece of code with the Save Button Code, which we demonstrated in the Blog Part III of this 5-part Blog series.
Lastly, the easiest of all – how to delete a record from any data source using Power Apps.
ATM Inspection PowerApp to ease ATM inspection and report generation process.
https://www.inkeysolutions.com/microsoft-power-platform/power-app/atm-inspection
Insert data into Many-to-Many relationship in Dynamics CRM very easily & quickly, using the Drag and drop listbox.
http://www.inkeysolutions.com/what-we-do/dynamicscrmaddons/drag-and-drop-listbox
Comply your Lead, Contact, and User entities of D365 CRM with GDPR compliance using the GDPR add-on.
https://www.inkeysolutions.com/microsoft-dynamics-365/dynamicscrmaddons/gdpr
Create a personal / system view in Dynamics CRM with all the fields on the form/s which you select for a particular entity using the View Creator.
http://www.inkeysolutions.com/what-we-do/dynamicscrmaddons/view-creator
© All Rights Reserved. Inkey IT Solutions Pvt. Ltd. 2024
[…] In the previous 4 blog parts, we have shown what data source we are using, Data Model View, how to connect to any data source in Power Apps, how to read data from any Data source, how to create records using the Patch method for column of any data type, how to update existing records from any Data source, and deleting a record from Data Source. You can check the forth part here. […]