Updating multiple CDS records from Grid using PowerApps
Introduction:
In this blog, we will learn how to Update multiple records of CDS from the Grid.
Use Case:
We have a requirement where there is a Grid of CDS Data Source, on clicking the Save Icon on top of the Grid, it should Save every record which is selected through the checkbox which is there on every record of the Grid.
Steps:
1. There is a Screen on which there is an Editable grid of Quote Product Entity.
- To Create an Editable Grid refer to the following link.
https://www.cloudfronts.com/create-an-editable-grid-view-in-powerapps/
- To add Lookup Fields in the Grid refer to the following link.
https://www.cloudfronts.com/add-lookup-fields-in-an-editable-grid-using-powerapps/
2. This is the grid with a checkbox.
3. To Save selected records, first create a Collection:
OnSelect property of the Delete icon:
Set SaveIcon.OnSelect = ClearCollect( <VariableName>, Filter( <GalleryName>.AllItems, <CheckBoxName>.Value = true ) ) For eg: SaveSelectedRecord.OnSelect= ClearCollect( SelectedQuoteProduct, Filter( GalleryQuoteProduct.AllItems, CheckboxQuoteProductGallery.Value = true ) )
4. When we select the Save Icon, it will collect all the records where the Checkbox is selected.
5. To Save the records from the CDS, set the OnSelect property of the Save Icon to the following formula:
OnSelect property of the Delete icon:
Set SaveIcon.OnSelect = ForAll( <CollectionVariable>, Patch( 'Gallery Data Source', <GUID you want to delete> { <fieldName>: TextInput.Text, <fieldName>:ComboBoxName.Selected, <fieldName>:Value(CurrencyTextInput.Text) } ) ) For eg: SaveSelectedRecord.OnSelect=ForAll( SelectedQuoteProduct, Patch( [@'Quote Products'], LookUp( [@'Quote Products'], 'Quote Product' in SelectedQuoteProduct[@'Quote Product'] ), { 'Product Code': ProductCodeQPGallery.Text, 'Product Name': ProductNameQPGallery.Text, Quantity: Value(QuantityQPGallery.Text), 'Sales Price': Value(SoldPriceQPEditform.Text), 'Discount Amount': Value(DiscountAmountQPGallery.Text), Tax:Value(TaxQPEditForm.Text), 'Extended Amount': Value(ExtendedAmountQPGallery.Text) } ) )
6. Combine the Whole formula in the OnSelect property of Save Icon :
For eg: SaveSelectedRecord.OnSelect= ClearCollect(
SelectedQuoteProduct,
Filter(
GalleryQuoteProduct.AllItems,
CheckboxQuoteProductGallery.Value = true
)
)
ForAll(
SelectedQuoteProduct,
Patch(
[@'Quote Products'],
LookUp(
[@'Quote Products'],
'Quote Product' in SelectedQuoteProduct[@'Quote Product']
),
{
'Product Code': ProductCodeQPGallery.Text,
'Product Name': ProductNameQPGallery.Text,
Quantity: Value(QuantityQPGallery.Text),
'Sales Price': Value(SoldPriceQPEditform.Text),
'Discount Amount': Value(DiscountAmountQPGallery.Text),
Tax:Value(TaxQPEditForm.Text),
'Extended Amount': Value(ExtendedAmountQPGallery.Text)
}
)
)
Conclusion:
Hope the above Blog helps you Save multiple records of CDS from the Grid.