web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Formula Help! ADD and ...
Power Apps
Answered

Formula Help! ADD and EDIT/SAVE buttons

(0) ShareShare
ReportReport
Posted on by 24

*Gallery1 is a list of projects; for each row there is a Risks/Issues button that navigates to a new screen with Gallery2 dynamically filtered for that project.

*Gallery2 has two custom fields autopopulated from Gallery 1: Project and ProjectID. There are several other fields too.

 

[Added note] Risks are created within the Gallery2 screen, so I think I have to populate the two fields upon row creation or it won't show in the active list.

 

I am struggling with the code to make the ADD button and EDIT/SAVE button work. Any ideas?

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @tuggehling 

    For the Add button:

    Patch(RiskIssues, Defaults(RiskIssues),{ProjectID:Gallery1.Selected.ID})

    For Gallery2, Sort(Filter(RiskIssues, ProjectID=Gallery1.Selected.ID), Descending)

    This will keep the newly created record at the top of the gallery. 

    For the Edit/Save button (on the same line as the records in Gallery2: Patch(RiskIssues, ThisItem)

    This will create a new blank line and put it at the top ofGallery

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @tuggehling 

    • For the Add button (Outside Gallery2):Patch(RiskIssues, Defaults(RiskIssues),{ProjectID:Gallery1.Selected.ID})
    • For Gallery2 Items property: Sort(Filter(RiskIssues, ProjectID=Gallery1.Selected.ID), Descending)  This will keep the newly created record at the top of the gallery.
    • For the Edit/Save button (on the same line as the records in Gallery2): Patch(RiskIssues, ThisItem)  
    • If you want a delete record, put a trash icon on the same line: Remove(RiskIssues, ThisItem)
    • To clean up the way the gallery looks, make the Visible property of the Edit button and trash icon: ThisItem.IsSelected

    !!.jpg

  • tuggehling Profile Picture
    24 on at

    This is so helpful, thank you! One final question if I may?

     

    1. For your solution on the Edit/Save button, are you saying to create an edit/save button within the gallery record? I have one in a different container that is intended to be a Edit All/Save All.

    2. I created a collection because I was having trouble patching and I followed a Reza Youtube video. Here is what I created for OnSelect for the edit/Save button:

     

    Set(varGridEdit,!varGridEdit);
    If(CountRows(colrisksissues)>0,
    Patch(
    'Risks and Issues',
    colrisksissues)
    );
    Notify("Success",
    NotificationType.Success
    ));
    Clear(colrisksissues);

     

    Given that, does your guidance change?

     

    This is so helpful, I really appreciate you.

  • tuggehling Profile Picture
    24 on at

    ok just reviewed your second post

     

    Here's where I'm at:

    I CAN add a new item

    I CANNOT edit the new item unless i select the toggling Save/Edit button outside of the gallery (minor)

    CAN click the toggling Save/Edit button and save the new record and changes to existing records

    Edits to existing records disappear when I click Add Row again or leave/reenter the app.

     

    Finally, each column in the Gallery is throwing an 'incompatible type' error in the update section:

     

    If(ThisItem.'Risks and Issues' in colrisksissues.crfc5_Risksandissuesid,
    Update(colrisksissues,
    LookUp(colrisksissues,crfc5_risksandissuesid = ThisItem.'Risks and Issues'),
    {
    crfc5_Risksandissuesid: ThisItem.'Risks and Issues',
    crfc5_LookupID: LookupDataCard,
    crfc5_riskorissue: TypeDataCard.Selected.Value,
    crfc5_name: TitleDataCard.Text,
    crfc5_description: DescriptionDataCard.Text,
    crfc5_riskorissuestatus: StatusDataCard.Selected.Value,
    crfc5_duedate: DueDatePicker.SelectedDate,
    Project: ProjectDataCard
    }),
    Collect(
    colrisksissues,
    {
    crfc5_Risksandissuesid: ThisItem.'Risks and Issues',
    crfc5_LookupID: LookupDataCard,
    crfc5_riskorissue: TypeDataCard.Selected.Value,
    crfc5_name: TitleDataCard.Text,
    crfc5_description: DescriptionDataCard.Text,
    crfc5_riskorissuestatus: StatusDataCard.Selected.Value,
    crfc5_duedate: DueDatePicker.SelectedDate,
    Project: ProjectDataCard
    }
    )

     

    I know I'm throwing a lot at you, but I made such strides with your last post and feel like I'm so close!!

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @tuggehling 

    What I suggested for Gallery2 was an editable grid for adding and editing records.  It does not use a collection or an edit form but instead, works with the datasource directly. I don't really know what you are doing with your model but I guess you are using a collection to store the changes and then updating the data source with it.  Some of the functions you mention seem to suggest that you have an edit form as well. 

  • tuggehling Profile Picture
    24 on at

    So I've simplified based on your input; removed the collection and the toggling Save/Edit button outside of Gallery 2. I am able to add rows, able to edit all of the fields, and navigate in and out of the screen. One problem persists: clicking the Save button doesn't see to commit the changes to the Dataverse table. As soon as I choose to add a new row or delete a room, the changes are gone. There's an error icon shown for the inline Save button that says "Network error when using Patch function: Value must be a data entity record. I can't find the error in the OnSelect code.

     

    I've tried your string:

     

    Patch(Risks and Issues, ThisItem)

     

    as well as adding all the variables from the gallery:

     

    Patch('Risks and Issues',{Project:ProjectDataCard_1,'Risk or Issue':TypeDataCard_1,Title:TitleDataCard_1,Description:DescriptionDataCard_1,'Risk or Issue Status':StatusDataCard_1,'Due Date':DueDatePicker_1})

     

    To no avail. At the risk of oversaturating my ask, any thoughts to get me over the hump?

     

    Again, thanks so much for your help. I think I'm trending towards intermediate because of you.

     

    tuggehling_0-1675720777495.png

     

  • mmollet Profile Picture
    3,187 on at

    Not sure if you are still getting the type mismatch error but if you are I would check out this line:

     

    crfc5_LookupID: LookupDataCard,

    Seems like you are setting the crfc5 column value to a control type rather than the value that control is storing. try using LookupDataCard.text or something like that and see if that clears up your type issue. Projectdatacard is the same way a little further down in your Update->object block of code.

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @tuggehling 

    Sorry for the delay in getting back to you.  Real life can interfere.  I believe you are getting errors because the values are already assigned during the ADD when the blank record is being added to the gallery.

    For the Add button outside the gallery, you want to initalize  the record by adding blanks to all the fields as defaults except the one that links to the parentID.  Also, make sure that dropdowns and/or comboboxes allow blank values.

     

    Patch(
     'Risks and Issues',
     Defaults('Risks and Issues'),
     {crfc5_risksandissuesid: Gallery1.Selected, 
     crfc5_riskorissue: Blank(),
     crfc5_name:Blank(),
     crfc5_description: Blank()
     crfc5_riskorissuestatus: Blank()
     crfc5_duedate: Blank()}
    );
    Refresh(Projects);

     

     

    For the Save button inside the gallery only data being input by the user should be in the patch:

     

    Patch('Risks and Issues',ThisItem,
     {crfc5_riskorissue: TypeDataCard.Selected.Value,
     crfc5_name: TitleDataCard.Text,
     crfc5_description: DescriptionDataCard.Text,
     crfc5_riskorissuestatus: StatusDataCard.Selected.Value,
     crfc5_duedate: DueDatePicker.SelectedDate}
    )

     

     

     

  • tuggehling Profile Picture
    24 on at

    Hi @Drrickryp ,

     

    I'm ALMOST there; I can add a new row, I can save an existing item, it's filtering correctly, etc. One remaining problem:

     

    It seems that the 2 selection box fields don't save upon patching, but the autopopulated fields, text fields, and date field do. 

     

    Patch
    ('Risks and Issues',ThisItem,
    {crfc5_riskorissue: TypeDataCard_1.Selected.Value,
    crfc5_name: TitleDataCard_1.Text,
    crfc5_description: DescriptionDataCard_1.Text,
    crfc5_riskorissuestatus: StatusDataCard_1.Selected.Value,
    crfc5_duedate: DueDatePicker_1.SelectedDate}) 

     

    I've tried all the following:

    .SelectedAllItems

    .Selected.Text

    .Text

     

    I cannot figure it out....

     

    tuggehling_0-1675883963512.png

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @tuggehling

    Shane Young has a new video out Patching complex column types. Check it out. https://youtu.be/gsk14D-CYRE 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 549 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 225 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 224

Last 30 days Overall leaderboard