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 to do a lookup onc...
Power Apps
Answered

How to do a lookup once in a forall()

(0) ShareShare
ReportReport
Posted on by 3,340

I want to ping the SQL table once per record.  Instead of a lookup for each column one at a time.  My forall() may get quite big.  I want to limit the server calls.

 

 

 

ClearCollect(AttachedFile_Data,ForAll(AttachedFile_PreData,
{ FileName: FileName,
 WO_Num: ThisRecord.WO_Num,
 SNRange: ThisRecord.SNRange,
 Filename: ThisRecord.FileName,
 WO_Line: ThisRecord.WO_Line,
 OrderNumberOB: ThisRecord.WO_Num&"-"&ThisRecord.WO_Line,
 ShouldBeName: "WO "&WO_Num&"-"&WO_Line&" "&SNRange&".pdf",
 GUIDOrder: LookUp('[dbo].[View_Orderboard_Acctivate]',OrderNumber=WO_Num And LineNumber=WO_Line).GUIDOrder,
 GUIDOrderDetail: LookUp('[dbo].[View_Orderboard_Acctivate]',OrderNumber=WO_Num And LineNumber=WO_Line).GUIDOrderdetail,
 FileNameCheck: If(SNRange=LookUp('[dbo].[View_Orderboard_Acctivate]',OrderNumber=WO_Num And LineNumber=WO_Line)._SNValve,true,false)
}

 

 

 

The statement above works, but I want to do a single lookup into a variable, then use variable.GUIDOrder and variable.GUIDOrderDtail, etc.  I'm sure there is a way to do this with a With() statement, but I couldnt place it in this statement in a place where it worked proper.  Well, I never resolved syntax problems.  

 

Helpie?


Thanks

Categories:
I have the same question (0)
  • Verified answer
    CU-18081211-6 Profile Picture
    9,270 Moderator on at

    @martinav ,

     

     

    ClearCollect(
     AttachedFile_Data,
     ForAll(AttachedFile_PreData,
     With({currentLookUp:LookUp('[dbo].[View_Orderboard_Acctivate]',OrderNumber=WO_Num And LineNumber=WO_Line)},
     { 
     FileName: FileName,
     WO_Num: ThisRecord.WO_Num,
     SNRange: ThisRecord.SNRange,
     Filename: ThisRecord.FileName,
     WO_Line: ThisRecord.WO_Line,
     OrderNumberOB: ThisRecord.WO_Num&"-"&ThisRecord.WO_Line,
     ShouldBeName: "WO "&WO_Num&"-"&WO_Line&" "&SNRange&".pdf",
     GUIDOrder: currentLookUp.GUIDOrder,
     GUIDOrderDetail: currentLookUp.GUIDOrderdetail,
     FileNameCheck: SNRange=currentLookUp._SNValve
     }
     )
     )
    )

     

     

    I think that you are aware that this function makes SQL query calls as many records AttachedFile_PreData has. 

     

    Hope it helps !

  • martinav Profile Picture
    3,340 on at

    @gabibalaban ,

     

    Hmm, this is what I did, and it broke.  I'll try again and see, and report back.

  • CU-18081211-6 Profile Picture
    9,270 Moderator on at

    @martinav ,

    If my proposal not works, please let me summon the @RandyHayes's power for a little help. 😊

  • martinav Profile Picture
    3,340 on at

    @gabibalaban ,

     

    I think I know why... i'll check in a bit.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @gabibalaban 

    It's looking good! It's the way to do it. 

  • Verified answer
    martinav Profile Picture
    3,340 on at

    Ok, I remember now.  doing the With() there breaks ThisRecord due to ambiguity.  The As varForAllValue in the ForAll() fixes this.  THanks @gabibalaban  and @RandyHayes !

     

     

    learCollect(AttachedFile_Data,ForAll(AttachedFile_PreData As varForAllValue,With({varLookupFirst:LookUp('[dbo].[View_Orderboard_Acctivate]',OrderNumber=varForAllValue.WO_Num And LineNumber=varForAllValue.WO_Line)},
    { FileName: varForAllValue.FileName,
     WO_Num: varForAllValue.WO_Num,
     SNRange: varForAllValue.SNRange,
     Filename: varForAllValue.FileName,
     WO_Line: varForAllValue.WO_Line,
     OrderNumberOB: varForAllValue.WO_Num&"-"&varForAllValue.WO_Line,
     ShouldBeName: "WO "&varForAllValue.WO_Num&"-"&varForAllValue.WO_Line&" "&varForAllValue.SNRange&".pdf",
     GUIDOrder: varLookupFirst.GUIDOrder,
     GUIDOrderDetail: varLookupFirst.GUIDOrderdetail,
     FileNameCheck: If(varForAllValue.SNRange=varLookupFirst._SNValve,true,false)
    }
    )))

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @martinav 

    Good catch!  I took a quick look once @gabibalaban included me on the post.  Sorry was knee deep in work that I didn't look closely for that...you are correct - in general, stay away from ThisRecord.  Use the As clause as much as possible.

    But, in the context of your formula, you don't need the As clause as each record generated in your ForAll will be generated in context of the AttachedFile_PreData records, so there is no collision. 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 534

#2
WarrenBelz Profile Picture

WarrenBelz 416 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 306

Last 30 days Overall leaderboard