cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
CPedersen
Level: Powered On

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

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
CPedersen
Level: Powered On

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

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.

View solution in original post

8 REPLIES 8
Super User
Super User

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

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!

CPedersen
Level: Powered On

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

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. 

Super User
Super User

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

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!

CPedersen
Level: Powered On

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

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. 

Super User
Super User

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

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?

CPedersen
Level: Powered On

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

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. 

Super User
Super User

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

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. 

CPedersen
Level: Powered On

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

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.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,207)