Skip to main content

Notifications

Power Apps - Building Power Apps
Unanswered

Edit Records and Save in collection

(1) ShareShare
ReportReport
Posted on by 986

Hi everyone,
I had created a screen in which employees can enter the work mode for the current week and save it (mainly 2 modes WFO - Work from Office and WFH - Work from Home), and accordingly the calculation of how many days did the employee WFH or WFO was displayed in the respective columns:

Sidhant_02_0-1675838396401.png

And when the user clicks on Save then the details are getting saved in a collection named FinalPayRollLines and a Notification message shown on Screen 'Your data has been saved successfully' and then navigated to another screen named TimeSheet Saved Screen_1. In this screen I have used a Data Table which is connected to the collection created which is FinalPayRollLines.

Sidhant_02_1-1675838667530.png

So what I want is to have a edit button at the top, and if a user wants to edit a record or make any changes after making the submission they can do it on this screen. 

Sidhant_02_2-1675839038209.png

 

Sidhant_02_3-1675839077725.png

 

So let's say we have data in the above screen for an employee, here Sam and he/she wants to change the work mode for Monday from WFH to WFO, so they select their record click on edit button and then they can make the changes which will get saved and they are navigated back to the same screen.
So can it be done, if so please let me know.

Regards,
Sidhant.


Categories:
  • KeithAtherton Profile Picture
    KeithAtherton 3,640 on at
    Re: Edit Records and Save in collection

    Try using the OnChange event yourself first so you can learn how it works and decide if it can be used for your needs.


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

  • Sidhant_02 Profile Picture
    Sidhant_02 986 on at
    Re: Edit Records and Save in collection

    Could you please provide example on how to check if a value is been changed using OnChange activity for TextInputs and then only saving those values instead of using Toggle

  • KeithAtherton Profile Picture
    KeithAtherton 3,640 on at
    Re: Edit Records and Save in collection

    The idea of using one screen where you can add, edit or delete data using one collection is a good one and worth trying.

     

    An alternative to comparing values for the toggle is to use the input controls' OnChange property to detect if a change has been made. Try this to see if it does what you need.


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

  • Sidhant_02 Profile Picture
    Sidhant_02 986 on at
    Re: Edit Records and Save in collection

    The second query was if I a create a new collection named Sheet instead of using collection name from previous screen named FinalPayRollLines, so in Toggle condition ThisItem.Attribute name cannot be used instead it will be blank over there. Instead of using 2 screens, I was thinking only one screen where in I can add, edit or delete data using one collection, (as currently I am using 2: TimesheetLines and FinalPayRollLines).
    By Default value of toggle is set to True:
    I did change the default value to false and try editing a record but the toggle was not showing any change:

    Sidhant_02_0-1676368469816.png

    So is there any alternative where in if any change is detected in the Input boxes on the screen, the toggle should switch to True:

    Sidhant_02_1-1676368604068.png

    (Because initially I used ThisItem.MonHrs which will refer to the current item/selected item value and compare with the new inputs given on the page, but instead if there is any change in any of the input boxes the toggle should be true.
    Also on selecting one of the values specified in the expression like ThisItem.MonHrs (which is from the previous screen: Refer to the image attached)

  • KeithAtherton Profile Picture
    KeithAtherton 3,640 on at
    Re: Edit Records and Save in collection

    Re the toggle: The code looks good, I would also expect to see the default value of false. To investigate this, select each of the values (ThisItem.MonHrs, mon.Text, etc) by selecting them in the formula bar to see why the condition is evaluated to true.

     

    Re the other query: Sorry, I don't understand why previous blank values need to be compared with new values.


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

  • Sidhant_02 Profile Picture
    Sidhant_02 986 on at
    Re: Edit Records and Save in collection

    Hi Keith,
    I created a new screen named TimeSheet Saved Screen_2 in this screen I took a blank vertical gallery with data source from previous screen which is TimeSheet_1 on its save I am collecting all the data in a collection named FinalPayRollLines_1
    New Screen created: TimeSheet Saved Screen_2

    Sidhant_02_0-1676357987672.png

    In the above screen data is coming from the previous screen which is TimeSheet_1:

    Sidhant_02_1-1676358054795.png

    And on it Save: the collection is created

    Sidhant_02_2-1676358089262.png

    It is working but now I wanted to check which record is getting changed and only those records should be saved so for that I was using a Toggle to compare values from previous screen and the new data entered (in the newly created screen) but even after making changes to Work mode in any column the calculation was done but toggle was not changing:

    For Toggle:

    Sidhant_02_3-1676358266594.png



    Sidhant_02_5-1676359689132.png

    So I am getting the expected requirement the only issue is toggle value is not working (so by default it should be false) but it is True, so is it because I am clearing the TimesheetLines_1 collection from previous screen, due to which it assuming all the values as blank and hence set to True?



    The next step that I was going to perform create a button to edit records, and save only records in the collection that are changed not all (but toggle is not working).

    Save:

    Sidhant_02_4-1676358516088.png

    On Save I want to save only those values which are modified on this screen not all.




    Also: The other query that I had lets say if I don't want to take FinalPayRollLines_1 as data source and create a new collection (sheet), and then here I want to compare previous values (blank) with new values and based on that update how to do it?. Because I tried creating a collection named sheet but was not sure about what value should I compare in Toggle condition with the new values in Text Input

  • KeithAtherton Profile Picture
    KeithAtherton 3,640 on at
    Re: Edit Records and Save in collection

    Yes, making the grid editable is an option which looks like the approach you're using to create new records.

     

    To make existing records editable, I would display them in the gallery by setting the gallery Items property to the data source. Then the user can edit the record using input controls (as you currently have), then a "save" button can be used to read the values from the input controls then call a Patch() method to update the existing record.


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

  • Sidhant_02 Profile Picture
    Sidhant_02 986 on at
    Re: Edit Records and Save in collection

    Hi @KeithAtherton ,
    In the previous screen where user enters the details (Working Status screen), I have used a gallery and after the data is saved I am navigating to the new screen named Work Mode. In Working Status screen I have used an Gallery named TimeSheetLines which is been saved in a collection:

    Sidhant_02_0-1676289509988.png

    Sidhant_02_1-1676289550111.png

    So what I understand is you are trying to say I should save the data in Working Status screen itself which is this:

    Sidhant_02_2-1676289640850.png

     

    So after entering the data, how should I display it on the screen and then if user wants to change a particular record how to that using the edit button which I have described above.

    Regards,
    Sidhant.

  • KeithAtherton Profile Picture
    KeithAtherton 3,640 on at
    Re: Edit Records and Save in collection

    Hi @Sidhant_02,

     

    Looks like the grid is a data table. Consider using a gallery with input controls so you can make changes directly in the grid then click a save button to call a Patch() method to save changes.

     

    This will also mean screen navigation is not required as the grid is used for viewing and editing.


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

  • Sidhant_02 Profile Picture
    Sidhant_02 986 on at
    Re: Edit Records and Save in collection

    Hi zmoerk,

    I don't want the user to navigate back to the first screen (TimeSheet_1) because on this screen I just want the users who have not entered any data for the current week to fill the timesheet. The users which have already entered the data and wish to make any changes can go on the second page which is TimeSheet Saved Screen and over there select the record they wish to change and then an edit button through which they will make the change and it will get saved over there.

    Regards,
    Sidhant

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Kickstarter Events…

Register for Microsoft Kickstarter Events…

Tuesday Tip #12 Start your Super User…

Welcome to a brand new series, Tuesday Tips…

Tuesday Tip #13 Writing Effective Answers…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,858

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,505

Leaderboard