How to Display Data Table in LogixPro and Delete Records in PowerApps
Are you looking for ways to display a data table in LogixPro and delete records from it in PowerApps while still maintaining the original records in your Common Data Service (CDS)? If so, this article will guide you through the process.
Displaying a Data Table in LogixPro
Firstly, let's discuss how to display a data table in LogixPro. To do this, you can use the `Gallery` control and bind it to your data source. In this case, since you are reading from a table in the Dataverse/CDS, you will need to create a connection to your CDS instance and then use the `FetchXML` function to retrieve the data.
Here's an example of how you can do this:
```
Gallery1.Items =
Patch('YourTable',
Filter(CDS.YourTable, 'Column1' = 'Value1', 'Column2' = 'Value2'),
{ColumnName: Value3}
)
```
In this example, `Gallery1` is the control that displays the data table, and `CDS.YourTable` is the name of your table in the Dataverse/CDS. The `Filter` function is used to retrieve specific records based on certain conditions.
Deleting Records from PowerApps Data Table
Now that you have displayed your data table in LogixPro, let's talk about how to delete records from it. To do this, you can use a `Button` control and set its `OnSelect` property to a formula that deletes the selected record.
Here's an example of how you can do this:
```
DeleteRecord =
ForAll(
Filter(Gallery1.Items, ThisItem.Selected),
DeleteItem(CDS.YourTable, ThisItem.ID)
)
```
In this example, `Gallery1` is the control that displays the data table, and `CDS.YourTable` is the name of your table in the Dataverse/CDS. The `Filter` function is used to retrieve the selected record(s), and the `DeleteItem` function is used to delete them.
Preserving Records in CDS
As you can see from the previous examples, deleting records from PowerApps will also delete them from the Dataverse/CDS if not handled properly. To preserve the original records in your CDS, you can use a separate table or entity that stores the deleted records.
Here's an example of how you can do this:
```
DeleteRecord =
ForAll(
Filter(Gallery1.Items, ThisItem.Selected),
Patch(
'DeletedRecords',
AddColumns({
ID: Text(ThisItem.ID, 'ID'),
RecordData: JSON(ThisItem, true)
}, ''ColumnName', Value3')
)
)
```
In this example, `DeletedRecords` is the name of a separate table or entity that stores the deleted records. The `Patch` function is used to insert new records into this table.
In conclusion, displaying a data table in LogixPro and deleting records from it in PowerApps while preserving the original records in your CDS is possible using the techniques described above. By binding the `Gallery` control to your data source and using formulas to retrieve and delete records, you can achieve this functionality. Additionally, by storing deleted records in a separate table or entity, you can ensure that they are preserved for future reference.