I want to insert a row using the following formula:
ClearCollect(TempName, { Name: "John"}, { Name: "Doe" }); Collect('[dbo].[Name]', TempName)
This will insert two rows into my SQL Server table Name.
(1, John) , (2, Doe)
I basically want to return the two ID's 1 and 2 into my application. Is this possible with PowerApps at present?
Solved! Go to Solution.
Hi @dcullen
Yes, it's possible to retrieve the ID values of the records that you insert.
Once the Collect function inserts the rows into the SQL table, it returns the contents of the table and this includes any auto-generated values from the data source.
For example, this formula would collect the results into a collection called ResultsTable.
ClearCollect(TempName, { Name: "John"}, { Name: "Doe" }); ClearCollect(ResultsTable, Collect('[dbo].[Name]', TempName))
Note that ResultsTable will include all other records from [dbo].[Name]. If you want to more precisely retrieve the ID value for the records that you insert, an alternative method is to insert single records by calling the Patch function. The Patch function returns the inserted record, which also includes the ID value.
Hi @dcullen
Yes, it's possible to retrieve the ID values of the records that you insert.
Once the Collect function inserts the rows into the SQL table, it returns the contents of the table and this includes any auto-generated values from the data source.
For example, this formula would collect the results into a collection called ResultsTable.
ClearCollect(TempName, { Name: "John"}, { Name: "Doe" }); ClearCollect(ResultsTable, Collect('[dbo].[Name]', TempName))
Note that ResultsTable will include all other records from [dbo].[Name]. If you want to more precisely retrieve the ID value for the records that you insert, an alternative method is to insert single records by calling the Patch function. The Patch function returns the inserted record, which also includes the ID value.
If you use a Collect call, then you cannot get the ids. You can use a Patch call, however, where it returns the item that was inserted (or modified), including the (identity) id field.
In your case you can have an expression like the one below:
ForAll( TempName, Collect( temp2, Patch( '[dbo].[Name]', Defaults('[dbo].[Name]'), { Name: Name })))
For each item in the TempName column, it will execute a Patch with the defaults for the table (which causes an insert operation), and collect the result into the temp2 collection. That collection will have the ids for the newly inserted items.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
189 | |
53 | |
51 | |
34 | |
33 |
User | Count |
---|---|
268 | |
92 | |
80 | |
68 | |
67 |