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 / Save item in gallery n...
Power Apps
Suggested Answer

Save item in gallery not working properly using collections

(1) ShareShare
ReportReport
Posted on by 603
I have a powerapp gallery which uses a collection. On click of Add button, i am adding blank rows in gallery. The issue which i am facing is clicking on save icon, saves other rows as well, instead of saving particular row which is selected. May i know how to avoid this?
 
Add button OnSelect
Collect(
    yourSOCollection,
    {
        Name: "",
        Email: "",
        Designation: "",
        Contact: "",
        RandID: Rand(),
        ID: Last(
            Sort(
                'System List',
                ID,
                SortOrder.Ascending
            )
        ).ID + 1
    }
)
Gallery Items Property
yourSOCollection
 
Edit icon inside Gallery OnSelect
UpdateContext({varEditItem: ThisItem.RandID})
Save icon inside Gallery OnSelect
Patch(
    yourSOCollection,
    ThisItem,
    {
        Name: TextInput4.Text,
        'Email': TextInput4_1.Text,
        'Designation': TextInput4_2.Text,
        'Contact': TextInput4_3.Text
    }
);
UpdateContext({varEditItem:0})
Form OnSuccess
ForAll(
    yourSOCollection As ITEM1,
    Patch(
        'SO Details',
        Defaults('SO Details'),
        {
            Title: ITEM1.Name,
            'SO Email': ITEM1.Email,
            'SO Designation': ITEM1.Designation,
            'SO Phone': ITEM1.Contact,
            System_List_ID: ITEM1.ID
        }
    )
);
 
Categories:
I have the same question (0)
  • Suggested answer
    jpespena Profile Picture
    335 on at
    Hi,
     
    Try:
     
    Edit icon inside Gallery OnSelect
    UpdateContext({varEditItem: ThisItem})
     
    Save icon inside Gallery OnSelect
    Patch(
        yourSOCollection,
        ThisItem,
        {
            Name: TextInput4.Text,
            'Email': TextInput4_1.Text,
            'Designation': TextInput4_2.Text,
            'Contact': TextInput4_3.Text
        }
    );
    UpdateContext({varEditItem: Blank()})
     
  • Iantaylor2050 Profile Picture
    603 on at
    Hi @jpespena
     
    No it doesnt work. If i click on edit icon on any of the row, all rows become editable. Same for save icon as well.
     
    It should only enable that row to become editable. Below is the code for DisplayMode property on textinput box.
     
    If(
        !IsBlank(varEditItem),
        DisplayMode.Edit,
        DisplayMode.View
    )
     
  • jpespena Profile Picture
    335 on at
    Hi,
     
    Yes, all rows become editable because of your current DisplayMode property since it's looking if varEditItem is not blank and it becomes true once you select any edit button. Try this:
     
    If(
        varEditItem.ID = ThisItem.ID,
        DisplayMode.Edit,
        DisplayMode.View
    )
     
    With your edit button has this on OnSelect:
     
    UpdateContext({varEditItem: ThisItem})
  • ronaldwalcott Profile Picture
    3,866 Moderator on at
    If your gallery uses a collection how are you saving items to the table?
    What is in your Submit form as OnSuccess doesn't run unless the Submit is successful?
    I don't believe that ADD selects an item in the gallery all it does is add an empty row.
    What value does this show when I presume you click the edit button
    UpdateContext({varEditItem: ThisItem.RandID})
     
    Does it show the new value or the last row which was selected?
    When you click Add you need to store the ID value of the new empty record and in the Patch lookup in the collection and do not use ThisItem.
     

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 899

#2
Valantis Profile Picture

Valantis 571

#3
11manish Profile Picture

11manish 499

Last 30 days Overall leaderboard