cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
marvinbarnuevo
Helper II
Helper II

ForAll() not working???

Hi,

 

I have a gallery and a button (outside the gallery).

 

The formula of the button is below: it just updates the existing records

ForAll(
QuoteProductGallery.AllItems,
{
Quantity: 3,
Quote: GUID(QuoteIdGuidLabel.Text)
}
)

 

Any help is appreciated.

 

Thanks!

16 REPLIES 16

@mdevaney 

 

PATCH also accepts 2 arguments - it means you are updating specific record. But regardless if I put 2 or 3 arguments in the PATCH, PowerApps always throw an error.

@marvinbarnuevo 

I understand you can use 2 arguments to "merge two records outside of a datasource" as shown in the official documentation like this. But please note that the first argument in this case is a Collection.

Patch({ Name: "James", Score: 90 },{ Name: "Jim", Passed: true })

 

You cannot supply only 2 arguments when your 1st argument is all Gallery1.AllItems.  AllItems is a property of the Gallery not a Collection. PATCH cannot update the AllItems property.

Patch(Gallery1.AllItems,{Quantity: 3})

 

If you want to change the contents of a gallery you must instead insert new records into the Collection being supplied to the gallery Items property or update its values.  But please note this would not change what is in the datasource called 'Quote Products'.

colQuoteProducts

 

You stated your goal was for the gallery records to be inserted into your datasource called 'Quote Products'.  To do this we should PATCH the values into the 'Quote Products' table like this.  Note: to do it this way your Gallery1 must have all the same columns as the datasource.

Patch(
    'Quote Products',
     Defaults('Quote Products'),
     Gallery1.AllItems
)

 

Or you can loop over the Gallery.AllItems and PATCH in only the fields needed leaving the rest as default.

ClearCollect(myCollection, QuoteProductGallery.AllItems)
ForAll(
    myCollection,
    Patch(
        'Quote Products',
        Defaults('Quote Products'),
        {
            SomeField1: myCollection[@SomeField1],
            SomeField2: myCollection[@SomeField2],
            Quantity: 3
        }
    )
)

 

Hopefully this info is helpful.  I am not trying to give a lecture here.  I am only trying to share my understanding of how the issue could potentially be solved.  I am trying my best for you!

 

I would be curious to see a screenshot of the error if you used this code.

Patch(
    'Quote Products',
     Defaults('Quote Products'),
     Gallery1.AllItems
)

 

 

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

Trying to solve issues over the forum sure can be tough right? I wish I could just walk over to your computer and try a few lines of code!

@mdevaney 

 

I really appreciate sharing your ideas and your effort! I am really open to suggestions/ideas so that's not a problem at all.

 

It is really tough but I will get what I can get.

 

Below is the error for the expression you are curious to see.

image.png

 

ClearCollect(myCollection, QuoteProductGallery.AllItems) ForAll( myCollection, Patch( 'Quote Products', Defaults('Quote Products'), { SomeField1: myCollection[@SomeField1], SomeField2: myCollection[@SomeField2], Quantity: 3 } ) )

This is actually close to my original expression when I was still using D365 connector. But got broken when I moved to CDS connector.

@v-xida-msft
Any ideas you can share with us about this problem would be greatly appreciated!

@mdevaney 

 

Below link resolves my issue. Instead of using 'Quote Products', [@'Quote Products'] should be used.

https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/ForAll-around-working-Patch-yields-...

 

ForAll(
    QuoteProductGallery.AllItems,
    Patch(
        [@'Quote Products'],
        {
            Quantity: 3,
            quotedetailid: GUID(QuoteProductIdLabel.Text)
        }
    )
)

 

View solution in original post

Good to hear it.  I learned something here too.  Thanks for providing the link.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (66,859)