web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Switch images with var...
Power Apps
Unanswered

Switch images with variable value

(0) ShareShare
ReportReport
Posted on by 44

Hi,

 

I am building a function that turn pages and have setup a switch function for the text on each page that works great. However when i try to setup the function for images it doesnt work and i am unable to figure out why.


Switch(varPage;1;ThisItem.Pic1;2;ThisItem.Pic2)

 

Pic1 and Pic2 are the column names. Each time i click the next button the variable increases by 1, so this function will go on for about 20 columns. Just using ThisItem.Pic1 works of course but when put in the switch function it doesnt, and the same function on the text field works great and switches between texts no problem.

 

Thanks for any help possible.

Categories:
I have the same question (0)
  • Bilakanti Profile Picture
    1,226 on at

    @DennisJarnstal - I would suggest to use variable inside switch and update the value to the same variable.
    Switch(varPage;1; Set(image,ThisItem.Pic1);2;Set(image,ThisItem.Pic2))

  • DennisJarnstal Profile Picture
    44 on at

    @Bilakanti where should i be updating this variable image? If i set the image value to image variable i need to update that variable switch somewhere else but i dont think i understand where i should do that.

     

    If i set the image value to the mentioned code it wont accept since its only setting variable but not using the variable.

     

    Setting it in the button for next gives an error, tried to set it up like this on the button: Set(varPage; varPage + 1) && Switch(varPage;1;Set(varImage;ThisItem.Pic1);2;Set(varImage;ThisItem.Pic2))

     

    Thanks for your quick reply earlier 🙂

  • Bilakanti Profile Picture
    1,226 on at

    @DennisJarnstal - Can you please share the screenshot if possible.

  • DennisJarnstal Profile Picture
    44 on at

    @Bilakanti Sorry if im explaining it poorly 🙂 I will explain more what i mean.

     

    The button that updates my current text fields has this code in the OnSelect field:

    Set(varPage; varPage + 1)

    and the text field change with this code in the Text field, this works fine:

    Switch(varPage;1;ThisItem.Textsid1;2;ThisItem.Textsid2)

     

    I am trying to update the image to change with the varPage update and tried putting the following in the image property:

    Switch(varPage;1;ThisItem.Pic1;2;ThisItem.Pic2)

    This however doesnt work, and I now tried your approach but I cant see where i would set and update a new variable for the image. I called it varImage in the code you mentioned and tried setting the image property to varImage and updateing it along with the varPage update in the OnSelect of the button, but that didnt work, and i tried the code directly in the image property aswell. I have images attached.

     

    DennisJarnstal_0-1674653646684.png

    DennisJarnstal_1-1674653690281.png

     

     

  • Akser Profile Picture
    1,546 Moderator on at

    Hi @DennisJarnstal,

     

    So Pic1, Pic2 are image columns in SharePoint and you are absolutely sure there are images stored in those columns? 

  • DennisJarnstal Profile Picture
    44 on at

    @Akser yes there are images in the image columns, but empty columns give no error when displayed so i dont think it needs to be, or am i incorrect? If i for example use Pic3 column, with ThisItem.Pic3, which has no image it just displays and emtpy image field in power apps but no error

  • Akser Profile Picture
    1,546 Moderator on at

    @DennisJarnstal can we try the following just for testing purposes?

     

    Let's introduce a test variable after you set your page variable:

     

    Set(varPage, varPage + 1);
    Set(varTest, false);
    Set(varTest, true);

     

     And use this instead

     

    If(varPage = 1 And varTest, ThisItem.Pic1, varPage = 2 And varTest, ThisItem.Pic2)

     

     

  • Bilakanti Profile Picture
    1,226 on at

    @DennisJarnstal Can you try it using If condition?

    If(varPage1 = 1, ThisItem.Pic1,If(varPage = 2,ThisItem.Pic2))

  • DennisJarnstal Profile Picture
    44 on at

    @Akser setting image as below screenshot gives an error that the value image is expected:

    DennisJarnstal_0-1674656515594.png

    button onselect to the below:

    DennisJarnstal_1-1674656626026.png

     

  • DennisJarnstal Profile Picture
    44 on at

    @Bilakanti I tried this function earlier, tried it again now just to be sure, but it doesnt work, says value image is expected.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard