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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How can I get ID of cr...
Power Apps
Unanswered

How can I get ID of created items using Patch() in a ForAll function? I cant invoke Set() inside ForAll()

(0) ShareShare
ReportReport
Posted on by 309

How can I get the ID of created items using Patch() in a ForAll function that goes through a collection? I can't invoke Set() inside ForAll().  I am trying to send an email for each item, with a deep link to a task screen.

 

 

 

ForAll(
 Collection, 
 Patch('List',Defaults('list'),
 {}
 )
)

 

 

 

 @Pstork1 @SudeepGhatakNZ @WarrenBelz 

Categories:
I have the same question (0)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Yemata,

     

    You could use the With() function instead to create a function scope variable:

     

    ForAll(
     CollectionName,
     With(
     {
     wRecord: Patch(
     ListName,
     Defaults(ListName),
     {ColumnName: ColumnValue}
     )
     },
     //Referencing the record ID would be done via wRecord.ID
     //You can use this reference within e.g. the Office365Outlook.SendEmailV2()function
     wRecord.ID
     )
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • Pstork1 Profile Picture
    69,657 Most Valuable Professional on at

    This is one of the spots where ForAll() proves that its not procedural. I would suggest calling a Power Automate Flow to create the items. Then you can easily have the flow create an array of the IDs and pass that back to Power Apps.

    @LaurensM use of With should work if you want to use the ID in the For All, but if you actually want to save it somewhere, like a collection I don't think you can using just Power Apps

  • CarlosFigueira Profile Picture
    Microsoft Employee on at

    ForAll(table, expression) returns a table with the result of the expression applied to each row of the table, so the result of your ForAll has all the records that had been inserted:

    Set(
     myInsertedRecords,
     ForAll(
     Collection,
     Patch('List', Defaults('List'), {})
     )
    )

    At that point you can use another ForAll to send an e-mail for each inserted record:

    ForAll(
     myInsertedRecords,
     Office365Outlook.SendEmailV2(
     recipient,
     subject,
     $"<h1>New record inserted!</h1><p>Click <a href='https://contoso.org/items/{ThisRecord.ID}'>here</a> to access it!</p>"
     )
    )

    You can also do it in a single ForAll expression as well:

    ForAll(
     Collection,
     With(
     { insertedRecord: Patch('List', Defaults('List'), {}) },
     Office365Outlook.SendEmailV2(
     recipient,
     subject,
     $"<h1>New record inserted!</h1><p>Click <a href='https://contoso.org/items/{insertedRecord.ID}'>here</a> to access it!</p>"
     )
     )
    )

    Hope this helps!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 345 Most Valuable Professional

#2
11manish Profile Picture

11manish 207 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 177

Last 30 days Overall leaderboard