How do I display an image contained in a table but corresponds to random row

Hi. I am trying to display an image in an app that is contained within an Airtable table. The issue is I need the image displayed to match the row of a random item that is pulled from the same table (but a different field). So, in my design, I have two buttons, the text for each pull a random item from either the OptionA field or the OptionB field in the table:

I can get the text of the buttons to show a random item as desired, but I can’t seem to get the image to show the corresponding image within the OptionAimg or the OptionBimg. You can see in the table I’ve tried using both the images as attachments in the table as well as a URL. This is what I have attempted:

For example, if the random item for OptionB is selected as Football, I want the image in the design to show the image in the same line as Football in Option B, but the image that’s in the OptionBimg field.

Thanks for any help!

The mistake you’re making is to get a random item of the list. Instead, you need to get a random integer from 1 to [number of rows in data source] and assign it to a variable, say randomRowNum. And then use that to get list item # [randomRowNum] and use [randomRowNum] as the row id for your [get value] blocks.

1 Like

Hi @tatiang , thanks for responding. Do you mean like this?

This doesn’t seem to work for some reason, and I can’t figure out why.

If not, I’m not sure how I can set a new variable (e.g. randomRowNum) without getting an integer from a specific column in the table rather than just get a random row number that I can reference later. I hope that makes sense.

Thanks again

This is what I meant:

Thanks again @tatiang , much appreciated. I have tried this:

However, the text on the buttons is being retrieved OK but the images are not. Am I using the wrong component to get images from a table? I could do it via the image URL too if that makes it easier.

That should work as long as:

  1. The values in OptionAimg and OptionBimg columns are valid cloud-hosted urls.
  2. You’re not running into a known bug that can cause Get Value blocks to return cached values instead of current data source values.

What’s an example of an image url you see displayed if you set a Label’s text to this?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.