cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jharville
Helper V
Helper V

Using Lookup To SharePoint List To Pull Attachment Based On Choice Field From Main List

 

Hello all!

 

I have a main SharePoint list, 'ConferenceRooms', that holds every room inside of our office's campus. Each row (item) in this list is a room.

 

jharville_0-1644006511027.png

--------------------------------------------------------------------------------------------------

 

In another SharePoint list, we have a list called 'Maps' that has 2 columns:

1) Title - the name of the map attachment

2) Attachments - the actual PNG attachment corresponding to the name of the file

 

jharville_1-1644006569350.png

--------------------------------------------------------------------------------------------------

 

What I am trying to do is:

We have 1000+ rooms in our campus, and it wouldn't make sense to manually upload 1000+ attachments in each room (under a new column) in our 'ConferenceRooms' list ... so we built the "Maps" column in our 'Conference Rooms' list to mirror items that have the same value in "Title" column of our 'Maps' list.

 

What we want to do is: IF the item selected in the "Maps" (choice-type) column of our 'ConferenceRooms' list has the same name as an item in the "Title" column of the 'Maps' list ... we want to pull the corresponding attachment from that item in the "Attachments" column of our 'Maps' list into our PowerApp.

 

What code/logic would help us achieve this? I've tried numerous ways so far but no luck. Thank you!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@jharville 

Sure thing...then you just need to reference that in your LookUp.

 

So, first, if you only have one attachment for the photo, then you can set the Image property to:

First(LookUp(Maps, Title = yourCurrentRecord.Map.Value).Attachments).Value

 

In the event that there is NO corresponding record in your Maps list, you might want to consider a "sample/default" image.  You can add that image in your media of the app and then you can set the Image property to:

Coalesce(
    First(LookUp(Maps, Title = yourCurrentRecord.Map.Value).Attachments).Value,
    yourSampleDefaultImage
)

 

If the lookup returns an image...that will be what is shown.  If not, then your "fill-in" image will be shown.

_____________________________________________________________________________________
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

7 REPLIES 7
RandyHayes
Super User
Super User

@jharville 

LookUp(Maps, Title = yourChoiceControl.Selected.Value).Attachements will give you the attachments of the item in your list.

Not sure how you want to use it from that point, but that will do what you need.

 

I hope this is helpful for you.

_____________________________________________________________________________________
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!

 

@RandyHayes 

 

Thank you for your response. We don't have a choice control within our PowerApp, but rather the choice is selected within our SharePoint list and is fixed once completed. Essentially, what we want to do is to pull up the attachment (which is a photo) into the Detail Form of each room in our PowerApp ... similar to the "Room Photo" section that you see in the following screenshot:

 

jharville_1-1644008753764.png

 

RandyHayes
Super User
Super User

@jharville 

Sure thing...then you just need to reference that in your LookUp.

 

So, first, if you only have one attachment for the photo, then you can set the Image property to:

First(LookUp(Maps, Title = yourCurrentRecord.Map.Value).Attachments).Value

 

In the event that there is NO corresponding record in your Maps list, you might want to consider a "sample/default" image.  You can add that image in your media of the app and then you can set the Image property to:

Coalesce(
    First(LookUp(Maps, Title = yourCurrentRecord.Map.Value).Attachments).Value,
    yourSampleDefaultImage
)

 

If the lookup returns an image...that will be what is shown.  If not, then your "fill-in" image will be shown.

_____________________________________________________________________________________
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!

 

@RandyHayes 

 

This is extremely helpful, I do have one last question though. What would go in place of "yourCurrentRecord" ? Would it be the item (room) that is selected from the Gallery to pull its details up? I'm guessing maybe a "thisitem" ?

 

First(LookUp(Maps, Title = yourCurrentRecord.Map.Value).Attachments).Value

RandyHayes
Super User
Super User

@jharville 
Well that depends!  You showed an image with the top part showing details about the Conference room.  How are you displaying that information?  For example, there is a label that shows the DisplayName...what is the text property of that control?

 

_____________________________________________________________________________________
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!

 

@RandyHayes 

 

I got it! Used my 'varThisItemGal' variable that was created earlier and it worked like a charm. Thanks again for your help Randy, you're the man!

 

RandyHayes
Super User
Super User

@jharville 

That was what I was looking for 😁

Glad you found what you needed!

_____________________________________________________________________________________
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!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (2,164)