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 / Creating New Records i...
Power Apps
Answered

Creating New Records in CE Using Canvas App, ForAll, and Patch

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I am currently trying to build a Canvas App for my users to create multiple quote products at once. The idea is as follows:

 

  • Gallery1 is a list of all Products in the system
  • ProductSearch is a text input to filter the products based on name/sku
  • ProductList is a collection of all selected products
  • Gallery2 is a list of all selected products, so a user may build their collection and visualize the products they've added. 
  • Button1 will be used after the user has selected the required products, and will create quote products for the quote that this app is embedded on. 

 

I am currently stuck at the last step, as my ForAll loop and Patch function are not linking the new quote products with the selected product for their row. I can't seem to get the Product record from Gallery1/collection and put that into each new, unique quote product. My formula is as follows:

 

ForAll(Gallery2.AllItems,

Patch([@'Quote Products'],

Defaults([@'Quote Products']),

{producttypecode:[@'Product Type'].Product},

{quantity:1},

{quotedetailname:Title4.Text},

{propertyconfigurationstatus:'Properties Configuration'.'Not Configured'},

{quoteid:ModelDrivenFormIntegration.Item},

{productid:LookUp([@Products], Name in ProductList.Name)},

{uomid:'Default Unit'}

)

)

 

I have tried using First( and LookUp( to match productid with the product selected in the collection, but it either fails to match via a lookup, or uses the first product in the collection to populate all subsequent quote products. 

 

I believe I am missing the correct lookup/relation function to attach my new quote products to the existing product, but I can't seem to figure it out. Any help would be appreciated. 

Categories:
  • rebeccas Profile Picture
    2,591 on at

    You have too many { in there. To patch a collection to a data source it is typically this:

     

    ForAll(CollName, Patch(SPLIst, Defaults(SPList),

    {SPColumn 1: CollColumn1, SPColumn2: CollColumn2, SPColumn3:CollColmn3}))

     

    Hope this helps you out!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I've tried with less {} and same result, although I understand typically the forall/patch functions have less. Also, I am attempting to integrate this in D365 CE which I believe is where most of my issues for lookups are coming from, not SharePoint. Thanks. 

  • rebeccas Profile Picture
    2,591 on at

    If it is just your LookUp portion that is giving you trouble then you will most likely need to set a variable and refer to that in your lookup part. It sounds like it isn't sticking when you click on it which is common. Same reason I never use Gallery.Selected in any of my apps. 

     

    Sounds like your close. Good luck!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks again for the reply! 

     

    I tried it with a Variable, but since I am doing a bulk create, it is just saving the last product selected as a var and setting all quote products to be that single product. 

  • rebeccas Profile Picture
    2,591 on at

    For your LookUp part? It looked like that was something outside your gallery...is that a field that is in your gallery it is referring to?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    The field outside of my gallery is a search field for the product list. 

     

    The Collection (Gallery 2) is a group of products that the user selected to add, and will be bulk created as quote products. I need each line in the collection to reference the product that was selected so that when the quote product creation process occurs, I can set the Existing Product (aka productid) as the selected product in the collection. 

     

    However currently I either get all the same product name, or no product is filled in at all. 

  • rebeccas Profile Picture
    2,591 on at

    So I have one that I think would accomplish what you need. I will explain how mind does and I hope it will help you think through how you could do. Mine is a Materials Requisition App. 

     

    The PM selects a Cost Code from a gallery (that has a list of the options), when they select one it sets a variable of what they selected. 

     

    Then they can see the text inputs that allow them to add a request to the collection. For each time they put in data and add to the collection for each item is using that variable that was selected for the cost code. At any time they can click a button to change the cost code. When they do it keeps everything in the collection they have so far but backs up a step. So it hides the gallery showing the collection, hides the text input boxes and takes them back to selecting the cost code. They select a different cost code and the variable is changed and they are back to adding more to the collection. When they are done it uses the ForAll and creates a new item for each line of that collection that is showing in the gallery. 

     

    I hope explained it good...I might should have done a quick GIF to show. Let me know if you think this will help and you need more detail or clarification. 

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I was able to find a solution that worked in this case. 

     

    The solution ended up being to rename the column in my collection (from productid to productid1 in this case). This allowed the Patch function to find and compare the correct columns in the lookup function. I set productid: in the patch function to LookUp([@Products], productid=productid1). This matched my productlist collection to the selected product, which allows me to update that lookup on the quote product record. Here is the final code.

     

    ForAll(

    RenameColumns(ProductList, "productid", "productid1"),

    Patch([@'Quote Products'],

    Defaults([@'Quote Products']),

    {producttypecode:[@'Product Type'].Product}, {quantity:Value(TextInput1.Text)}, {quotedetailname:Title4.Text}, {propertyconfigurationstatus:'Properties Configuration'.'Not Configured'}, {quoteid:ModelDrivenFormIntegration.Item},  {productid:LookUp([@Products], productid=productid1)}, {uomid: 'Default Unit'}))

     

    You can enclose all fields in one set of {} or indepdently like above and both will work. I also added a Clear(ProductList) at the end to clear the users selections in case they want to add more products in the future.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 350 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 318

#3
Mohsin Ali Profile Picture

Mohsin Ali 220

Last 30 days Overall leaderboard