Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

Save item in gallery not working properly using collections

Posted on by 490
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:
  • ronaldwalcott Profile Picture
    ronaldwalcott 903 on at
    Save item in gallery not working properly using collections
    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.
     
  • jpespena Profile Picture
    jpespena 264 on at
    Save item in gallery not working properly using collections
    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})
  • Iantaylor2050 Profile Picture
    Iantaylor2050 490 on at
    Save item in gallery not working properly using collections
    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
    )
     
  • Suggested answer
    jpespena Profile Picture
    jpespena 264 on at
    Save item in gallery not working properly using collections
    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()})
     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,297

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,890

Leaderboard