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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Create a collection on...
Power Apps
Suggested Answer

Create a collection on click of add button and save the collection to list

(0) ShareShare
ReportReport
Posted on by 531
Need to create a collection on click of add button. The collection should allow me to add only 3 empty rows into it. If i add more than 3 rows, it should show me warning.
 
Once 3 rows are added, i should be able to edit those rows and add details into it. Something similar to below. 
 
On click of submit button in the form, the collection should get saved to the SharePoint list in backend.
 
 
May i know how to achieve this?
 
 
 
Categories:
I have the same question (0)
  • Iantaylor2050 Profile Picture
    531 on at
    Hi All,
     
    Can please help me on the above?
  • Suggested answer
    LessCodePaths Profile Picture
    100 on at
    Hi,
     
    I would recommend this:
     
    "Add" button:
    OnSelect - add blank row to collection
    Collect(yourCollection, {Name: "", Email: "", Designation: "", Contact: "", ID: Blank()})
    Visible - hide button when there are 3 rows in the collection
    CountRows(yourCollection)<=3
     
    1. Patching rows separately
    "Save" icon in each row:
    OnSelect - save to SharePoint and recognize it is required to create new or update existing row
    Patch(
        YourSharePointList,
        //define if new row should be created or existing row updated
        If(
           IsBlank(ThisItem.ID),
           Defaults(YourSharePointList),
           LookUp(YourSharePointList,ID=ThisItem.ID)
        ),
        {
            Title: ThisItem.Name,
            Email: ThisItem.Email,
            Designation: ThisItem.Designation,
            Contact: ThisItem.Contact
        }
    );
     
    2. Patching rows at once - Bulk patch
    "Save" icon below the gallery
    Patch(
        YourSharePointList,
        ForAll(
           YourGallery As Items,
           {
                 Title: TitleBox.Text,
                 Email: EmailBox.Text,
                 Designation: DesignationBox.Text,
                 Contact: ContactBox.Text,
                 ID: Items.ID
                 //based on this ID column SharePoint automatically know if new record should be created or existing should be patched re
                 
           }
        )
    )
     
    Hope it helps
    L.
  • Iantaylor2050 Profile Picture
    531 on at
    Hi,
     
    I tried above code but its not working. If i click on edit button inside gallery, it should allow me to edit only that row and not other rows. Currently if i click on individual edit button, it allows me to edit all rows. 
     
    Also on form submit button, it saves 3 rows in datasource, however all 3 rows are blank, despite collection being populated with below rows. May i know why?
     
    Add button OnSelect
     
    Collect(
        yourCollection,
        {
            Name: "",
            Email: "",
            Designation: "",
            Contact: ""
        }
    )
     
    Add button Displaymode (to allow only 3 rows to be added)
     
    If(
        CountRows(yourCollection) < 3,
        DisplayMode.Edit,
        DisplayMode.View
    )
     
    Gallery Items property
    yourCollection
    Gallery Edit icon
    Set(editenabled,true)
    Form Submit button
    Patch(
        'User Details',
        ForAll(
            yourCollection As Items,
            {
                Title: 'Name'.Text,
                'Email': 'Email'.Text,
                'Designation': 'Designation'.Text,
                'Phone': 'Contact'.Text,
                User_List_ID:Form1_9.LastSubmit.ID
            }
        )
    )
     
  • LessCodePaths Profile Picture
    100 on at
    Could you clarify which part does not work?
    If I would like to sum it up:
    1. You are able to add blank rows to the gallery and restrict rows count to 3
    2. You are able to save the rows to the SharePoint when editing is done. 
     
    If you want to edit rows separately, I advise add new column RowGuid to yourCollection
    Collect(
        yourCollection,
        {
            Name: "",
            Email: "",
            Designation: "",
            Contact: "",
            RowGuid: GUID()
        }
    )

    Then you can set variable on edit icon to specify which record is in edit mode:
    EditIcon.OnSelect
    Set(
       varGuidInEditMode,
       ThisItem.RowGuid
    )
    This variable should be used in DisplayMode property on all text inputs:
    TextInput.DisplayMode
    If(
       ThisItem.RowGuid=varGuidInEditMode,
       DisplayMode.Edit,
       DisplayMode.View
    )
    Then, when you are done with editing, you should clear varGuidInEditMode variable:
    Set(
       varGuidInEditMode,
       Blank()
    )
     
    I'm not sure about Save.
    It is working as expected? Are you want to save the data to SharePoint at once or row by row?
     
    L.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard