cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Unable to use a lookup in collection

Hi all,

I've been stuck on this for a while now and hope you guys have some insight as to why my code isn't working.

 

Basically i'm collecting records with 2 lookups from a gallery using checkboxes

 

However, when using forall in the checkbox collection to patch a new record one of the lookups doesnt find the table, even though autofill completes it. Quite sure the code is correct LookUp(Table,Field=something) As it does work outside of the for all collection.

 

Any idea's? One field matches, the other doesnt.

1 ACCEPTED SOLUTION

Accepted Solutions

@dpjatoch 

Depending on your column names, it would essentially be like this:

With({_location: LookUp(bx_Location, Name=varLoc)},
    Patch(Voorraad,
        ForAll(Coll_Checked As _item,
            With({_account: LookUp(account, 'Account Name'= _item.'Account Name')
            {
             voorraad: voorraad,
             bx_Location: _location,
             bx_name: _item.bx_name,
             bx_productnumber: _item.bx_productnumber,
             bx_supplier: _account
            }
        )
    )
)  
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

18 REPLIES 18

@dpjatoch 

Can you supply the formulas you are working with and having problems and a little more detail on what is not working properly (i.e. what the results are that you're seeing)?  This would be helpful as you are mentioning collections and ForAll.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi Randy,

I was just reading one of your posts about using ForAll wrong ( Using it like a for each in normal development languages).

 

What I'm trying to do is patch all records in my collection to a new Location, preferably "merging" them to an existing record if it exists based on some checks.

 

ForAll(
Coll_Checked,
Patch(
Voorraad,

{
bx_Location: LookUp(bx_Location,Name=varLoc),
bx_name: ThisRecord.bx_name,
bx_productnumber: ThisRecord.bx_productnumber,

bx_supplier: LookUp(account,'Account Name'=ThisRecord.'Account Name')
}
)
);

 

I cut out some things for readability. Basically the account lookup is working fine, the other isnt. I understand that my logic is wrong, according to some of your posts.

 

Would the correct logic be : 

 

First filter to find a matching record
Then patch for all?

 

edit:
Forgot to thank you for your time! Thank you in advance

@dpjatoch 

No problem on the time - happy to help!

 

Yes, the ForAll in your formula is backward and will lead to poor performance and issues.

Your formula should be: 

With({_location: LookUp(bx_Location, Name=varLoc)},
    Patch(Voorraad,
        ForAll(Coll_Checked As _item,
            With({_account: LookUp(account, 'Account Name'= _item.'Account Name')
            {
             bx_Location: _location,
             bx_name: _item.bx_name,
             bx_productnumber: _item.bx_productnumber,
             bx_supplier: _account
            }
        )
    )
)    

 

I assume you are working with DataVerse and not SharePoint!?

 

The above will perform much better just to begin with as the common lookup is done just once rather than every record from your collection.  The other Lookup is then done record by record.  The ForAll produces a table that is given to the Patch function to then (in this case) create a new record.

I assume you are creating records...if not, what is the primary key of your list/table?

 

Also, if you are working with a collection, then the ForAll can all be skipped if your collection has the same schema as the list/table.  But that is a different story.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you so much, 

 

I am indeed working with dataverse. 

 

The collection has the same data as the list/table. Might just do it without forall then. (so my selected collection will all get processed either way?)

 

I do want to make it a bit more complicated. Seeing as this is about products(productamounts), what i'm trying to do is actually "move" products to a different location, but preferably merge them if that location already exists. Do you think it will work like this? 


I didn't add it earlier but i'm also counting numbers. In single transfers im just calculating old + new. Will this also work in the same way? 

#1 - 1 + 2

#2 - 3 + 6

#3 - 9 + 10

 

Apologies if my post is a bit chaotic, long day trying to solve this 😁

 

 

 

@dpjatoch 

You can certainly use just the collection (i.e. Patch(yourTable, yourCollection) ) but the key to that is the collection needs to not only have the exact schema and proper value types, but it also needs the primary key.

If you collect it with a direct pull from the table (i.e. Collect(yourCollection, yourTable) ) then the collection will be "pure" and work.  If you manipulate the collection in other ways (such as creating your own column names or transposing data types) then it will not work properly and a ForAll is a great tool to reverse and normalize it.

 

As for moving to another location...this will all work except...you don't want to deal with the primary key.  You will want to blank it out in order to create new records.

In the case of a merge, then you want to pre-lookup and populate the primary key.

 

For example, (I will use ID as the primary key for simplicity), the following will merge records based on a Title:

Patch(newList,
    ForAll(oldList As _item,
        Patch(_item, {ID: LookUp(newList, Title=_item.Title, ID)})
    )
)
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

My primarykey is a guid, but I did an autonumber column because I found that the guid was not easily used or matched.


I guess I don't manipulate the collection (If i check data inside of it, it has the exact data I want). However for lookups you do need to match part of the lookup to text. 

 

I have written code to change a single record, which correctly matches. isn't this the same, except I will need to use the whole checkbox collection as my basis now?


Tomorrow I'l give it another look. Thank you so much for all your help, it was very educative.

@dpjatoch 

Yes, if you have a collection based on original values, then you can just use that.  

You mention this is a "Checkbox collection"...if you are trying to collect records from a Gallery of items when a box is checked, then you can even do away with all of that extra work.  The Gallery already is a table/collection.  It can be used as the basis for a patch with a filter for only items that are checked.

 

Yes, give some things a go again tomorrow and respond back with questions.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi Randy,

 

I'm trying to adapt the code you wrote in your previous post, it doesn't work though.

 

or example, (I will use ID as the primary key for simplicity), the following will merge records based on a Title:

Patch(newList,
    ForAll(oldList As _item,
        Patch(_item, {ID: LookUp(newList, Title=_item.Title, ID)})
    )
)

 

 

Patch(Voorraad,
ForAll(Coll_Checked As _item,
Patch(_item,
{ex_Locatie: LookUp(Locatie,Name=varLoc2)}
)
)
)

This results in an error for me, stating invalid arguement (Table), expecting a record instead.

Hi Randy,

 

I'm trying to adapt the code you wrote in your previous post, it doesn't work though.

 

or example, (I will use ID as the primary key for simplicity), the following will merge records based on a Title:

Patch(newList,
    ForAll(oldList As _item,
        Patch(_item, {ID: LookUp(newList, Title=_item.Title, ID)})
    )
)

 

 

Patch(Voorraad,
ForAll(Coll_Checked As _item,
Patch(_item,
{ex_Locatie: LookUp(Locatie,Name=varLoc2)}
)
)
)

This results in an error for me, stating invalid arguement (Table), expecting a record instead.

 

 

I've also tried the other part, but I can't reach any fields except the ones I add in the with.

 

dpjatoch_1-1657206314900.png

So I can only reach the location and supplier table

 

 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,181)