Add New Line Items to Repeating Tables in Power Apps and SharePoint List

I recently received feedback from the community asking how to add new line items to repeating tables when you want to update an existing item in Power Apps using SharePoint Lists. In this blog post, I’ll show you how to implement this feature in your Power Apps app. I’ll focus on the EditScreen.

If you’re unfamiliar with repeating tables, I recommend checking out my previous blog posts on setting them up.

FOR THE EDITSCREEN

In the EditScreen advanced properties OnVisible, set this function:

Edit Screen
Add New Line Items to Repeating Tables in Power Apps and SharePoint List

What it does: The editcolinvoice collection will have the table of records from the SharePoint list, but we only show selected columns that we need in our forms.

The item of our EditGalleryItems is Filter('Child Lists', DatacardValue1.Text = Title). It means getting the data from the filtered ‘Title,’ which is the Reference ID of the Master Lists, to the ‘Title‘ field of the Child Lists.

Edit Gallery Items
Add New Line Items to Repeating Tables in Power Apps and SharePoint List

I’ve added a new button inside the EditGalleryItems this button will have a function in OnSelect properties:

If(
    IsBlank(
        LookUp(
            editcolinvoice,
            ID = ThisItem.ID
        )
    ),
    Collect(
        editcolinvoice,
        ThisItem
    )
);
UpdateIf(
    editcolinvoice,
    ID = ThisItem.ID,
    {
        ID: ThisItem.ID,
        Title: DataCardValue1.Text,
        cldItemName: txtItemName.Text,
        cldPrice: Value(txtPrice.Text),
        cldQty: Value(txtQty.Text),
        Paid: chkeditPaid.Value,
        'Payment Method': rdeditPaymentMethod.Selected
    }
);
Edit Gallery Items
Add New Line Items to Repeating Tables in Power Apps and SharePoint List

What it does: This function will update the item in the editcolinvoice. If the ThisItem.ID is unavailable in the collection; it will create a new one; if it exists, it will update.

Set the Button3 visibility to false.

Button 3 
Add New Line Items to Repeating Tables in Power Apps and SharePoint List

In each of the controls, for text input and radio button, set the function in OnChange to

Select(Button3)
On Check
On Uncheck
Add New Line Items to Repeating Tables in Power Apps and SharePoint List

As for the check box, set the OnCheck and OnUncheck properties to

Select(Button3)

Whenever there are changes to the control, it will select Button3, which will update the editcolinvoice collection.

Add a new button outside the EditGalleryItems. You can rename this button like the one we added inside the gallery. The text for the button is + New line item.

Edit Gallery Items
Add New Line Items to Repeating Tables in Power Apps and SharePoint List

The function for the OnSelect is

If(
    CountRows(editcolinvoice) > 0,
    Patch(
        'Child Lists',
        editcolinvoice
    )
);
Patch(
    'Child Lists',
    Defaults('Child Lists'),
    {
        Title: DataCardValue1.Text,
        cldItemName: ""
    }
);
Clear(editcolinvoice);
Set(
    varReset,
    false
);
Set(
    varReset,
    true
);

What it does: Any gallery changes will reflect on the Child List first. It will then create a new empty item except for the Title in the Child List in SharePoint and add a new line in the gallery. However, we need the varReset variable to reset the gallery, so we add this to the EditGalleryItems function.

The EditGallery items will be changed from Filter('Child Lists', DatacardValue1.Text = Title) to

Filter('Child Lists', DatacardValue1.Text = Title && varReset)
Edit Item Form
Add New Line Items to Repeating Tables in Power Apps and SharePoint List

As for the OnSuccess of the EditItemForm, set the function.

If(
    CountRows(editcolinvoice) > 0,
    Patch(
        'Child Lists',
        editcolinvoice
    )
);
ResetForm(Self);
Clear(editcolinvoice);
RequestHide();

Add New Line Items to Repeating Tables in Power Apps and SharePoint List

Save and Publish it. 

About the Author

I am working as Productivity Analyst focus on SharePoint, Power Platform (Power Apps, and Power Automate) and Microsoft 365. Dual MVP (Business Applications & Microsoft 365 Apps & Services).

Reference

Cerbolles, A., 2023, ADD NEW LINE ITEMS TO REPEATING TABLES IN POWER APPS AND SHAREPOINT LIST, Anjcerbolles.com, Available at: https://anjcerbolles.com/2023/07/31/add-new-line-items-to-repeating-tables-in-power-apps-and-sharepoint-list/ [Accessed on 7 September 2023]

STAY UP TO DATE

Catch up on the latest blogseBookswebinars, and how-to videos.
Not a member? Sign up today to unlock all content.
Subscribe to our YouTube channel for the latest community updates

Share this on...

Rate this Post:

Share: