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 / Lookup based on Galler...
Power Apps
Unanswered

Lookup based on Gallery always taking the first record

(0) ShareShare
ReportReport
Posted on by 14

Dear all, 

 

I struggling with the following situation :

 

Instructions

ReferenceName
C-VIK-015Instruction Card 1
C-VIK-016Instruction Card 2
C-VIK-017Instruction Card 3

 

Performed Instructions with the following columns

ReferenceInstruction Reference 
 Lookup towards Instruction table 

 

I have a gallery based on a collection where all performed instruction are listed.

What i want to do is patch this to the table Performed Instruction.

 

I've written the following code to achieve this 

 

 

ForAll(
 GalInstrInsp.AllItems,
 Patch(
 [@'Inspection Instructions'],
 Defaults([@'Inspection Instructions']),
 {
 Reference: GUID(),
 'Instruction Reference': LookUp(colInstructions,Reference in GalInstrInsp.AllItems.Reference)
 }
 )
);

 

 

In the collection of the gallery following records are shown (reference is not displayed in the gallery)

 

Instruction Card 1

Instruction Card 3

 

When i patch, the result in the performed inspection table is two times C-VIK-015.  It seems that my code is not taking the next record.

 

Does someone has a solution for this ? 

 

Kind regards

 

Steve

 

 

 

 

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

    @Dycons 

    If your Gallery already has all the references listed, then why are you trying to look up the value in a collection?  What is the purpose of the collection?

     

    As I see if from what you have, your formula should be the following:

    Collect('Inspection Instructions',
     ForAll(GalInstrInsp.AllItems,
     {
     Reference: GUID(),
     'Instruction Reference': 'Instruction Reference'
     }
     )
    );


    The real question though on if this is successful will be based on the Items property of the Gallery.

    So, if this is not working, please provide that property formula.

     

    I hope this is helpful for you.

  • Liquid error: Exception has been thrown by the target of an invocation. Dycons Profile Picture
    14 on at

    Dear Randy, 

     

    My gallery is not showing the "Instruction Reference" field.

    I tried your solution but doesn't seems to work for me.

    Dycons_0-1620404544310.png

    To provide a little more information,

     

    The gallery is based on a collection witch is created OnStartUp

     

     // Create Collection to display instructions in Instruction Screen - Instruction Gallery
     ClearCollect(
     colInstructions,
     AddColumns(
     Instructions,
     "InstructionSelected",
     false
     )
     ),

    Instructions is a table in dataverse

    Dycons_1-1620404774317.png

    Gallery is based on colInstruction

    Dycons_2-1620404872580.png

    I want to save in a dataverse table the two records above (where the instruction reference is not showing in the gallery).  The field instruction reference in the inpection instruction table is a lookup towards the inspection table.

     

    Hope this will clear out a little more.

    Kind regards

     

    Steve

     

     

     

     

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

    @Dycons 

    Hi Steve!

    I am not understanding the purpose of the collection in this case.  What is the added column for?

    I'm a little confused over the sentence:

    "The field instruction reference in the inspection instruction table is a lookup towards the inspection table."

    I am not seeing the Inspection Instruction lookup in your picture of your table columns.  Am I missing something there?

  • Dycons Profile Picture
    14 on at

    Hey Randy, 

    Thanks again for your quick reply.  Let me try to explain more in detail:

    1. I have a kind of master data table "instructions" where all possible instructions are stored.

    Dycons_0-1620458056026.png

    Following data is present in the table

    Dycons_1-1620458163540.png

    2. OnStart, I've added the instruction table into a collection and added a column to it 

    ClearCollect(
     colInstructions,
     AddColumns(
     Instructions,
     "InstructionSelected",
     false
     )
     ),

    The reason for this is to achieve the following flow in my canvas app

    Dycons_2-1620458713211.png

    3.  Now i want to save the colInstructions (selected = true), so the records showing in my gallery towards the following table :

    Dycons_3-1620459025991.png

    Because instruction reference field in the inspection instruction table (save destination), i thought i had to do a lookup towards the instruction table based on the record in the gallery. (GalInstrInsp.AllItems.Reference)

     

    ForAll(
     GalInstrInsp.AllItems,
     Patch(
     [@'Inspection Instructions'],
     Defaults([@'Inspection Instructions']),
     {
     Reference: GUID(),
     'Instruction Reference': LookUp(colInstructions,Reference in GalInstrInsp.AllItems.Reference)
     }
     )

    The result is that always the first retrieved item set for instruction reference

     

    Hope this will clarify some things out.

     

    Kind regards 

     

    Steve

     

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 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard