Obtaining an image from a specific row in a column

Is there a way to put an image from a specific row into a template? I have a situation where I want to load one of 8 different images in a automation email template. The images are chosen from numbered columns but I notice that if I just reference <<image1>> for example, it tries to find that in the current row. As they are the same image every time (1-8) I don't want to have to load them afresh in each row. I just want Appsheet to go and fetch them from the single row where they are stored.

thanks for any help

James

Solved Solved
0 21 421
1 ACCEPTED SOLUTION

There is no need to use slice, just the table name is enough. I made a quick test with your setup, and the image works. I used..
<<Start: SELECT(Data[ID],[ID]=โ€xxxโ€)>>
<<SWITCH([ImageSelection],1,[Image1],2,[Image2],โ€โ€)>>
<<End>>

The structure is like this..

AleksiAlkio_0-1695102421574.png

View solution in original post

21 REPLIES 21

Yes, in general it should be possible. 

You could create a slice called say  "Image_Row_Slice" on the table that has images with a slice filter expression something like [_ROWNUMBER]=2 

This assumes , the single row where the app will store images has [_ROWNUMBER] =2 . You  could suitably change the filter expression to select a single row.

Then the template expression to display images could be 

<< ANY(Image_Row_Slice[image 1])>>  

<< ANY(Image_Row_Slice[image 2])>>  

and so on

 

Another way is to read those images directly on your template. Don't know your column/table structures, but something like..
<<IF: [Image1]=TRUE>><<LOOKUP("Keyvalue",Images,ID,Image1)>><<EndIF>>

Hi Aleksi,

One thought behind suggesting slice was , the template seems to be having 8 images to be always displayed. So instead of performing 8 SELECT() s , the slice could possibly save on those 8 SELECT()

Of course, I am sure you have another valid useful reason behind your recommendation that I might have missed.

Just trying to keep the app as simple as possible as the template is generated just now and then. And if all 8 images are always shown, then there is no need to use IF: & EndIf.

Okay , got it. Thank you. I think the app creator will analyze options based on her/his use case. A simpler template may work of lesser number of records. An additional step of slice may be useful in case the table has many records.

I feel like I've nearly solved this, but I'm struggling to get the template to display the email.

I'm using a Switch in the template like this:

<<SWITCH([ImageSelect],
"1",(Image_Row_Slice[Image1]),
"2",(Image_Row_Slice[Image2]),
"")
>>

When the email comes through, it doesn't display the image itself, but this line:

Image_Row_Slice::PlrTest_Images/93f5fbc8.Image1.142322.jpg

 
What am I missing?

Plesse try

<<SWITCH([ImageSelect],
"1",(ANY(Image_Row_Slice[Image1])),
"2",(ANY(Image_Row_Slice[Image2])),
"")
>>

It gives this line instead:

https://www.appsheet.com/image/getimageurl?appName=PlrTest-5663539&tableName=Image_Row_Slice&fileNam...

It seems that it's trying to load a reference to the image of varying formats rather than the actual image?

 

When reading image from another table, one way is to use Start & End. Something like..

<<Start: SELECT(Data[KeyColumn],[KeyColumn]=โ€xxxxxxโ€)>><<SWITCH([ImageSelect],โ€1โ€,[Image1],โ€2โ€,[Image2],etc.)>><<End>>

Right - what's happening in your select statement, I'm not clear how that relates to using a slice? What is Data and KeyColumn in your example please?

Data = Your table name where images are
KeyColumn = That table's key column name

Thanks, but I'm not sure how that helps. I've got 8 possible image columns to choose from, named Image1...Image8.

The correct image to use is stored in row 2 of each of those 8 columns.

I'm not clear what I would put in the KeyColumn=xxxx bit? I want to choose an image column from the number in the switch.

The "xxxxxx" is your key column's value in row #2 so the SELECT() picks only that one row. Then it picks the correct image column depending on your number in ImageSelect column.

Tried this variant as well:

<<Start: SELECT(Image_Row_Slice[ID
],[_RowNumber
]=โ€2โ€)>>
<<SWITCH([ImageSelect],
1,[Image1],
2,[Image2],
"")
>><<End>>

No effect.

I suspect a slice can't bring across an image.

There is no need to use slice, just the table name is enough. I made a quick test with your setup, and the image works. I used..
<<Start: SELECT(Data[ID],[ID]=โ€xxxโ€)>>
<<SWITCH([ImageSelection],1,[Image1],2,[Image2],โ€โ€)>>
<<End>>

The structure is like this..

AleksiAlkio_0-1695102421574.png

Thanks, it doesn't work on mine. This is the code I'm using, I tried with double quotes around the value and without. The fields and values are all correct, it doesn't complain of an error and runs but no image is loaded in the template. ImageSelect is of type Number so it is correct not to have quotes around the values.

The template loads everything else. Very puzzling.

<<Start: SELECT(PlrTest[ID],[ID]=โ€93f5fbc8โ€)>>
<<SWITCH([ImageSelect],1,[Image1],2,[Image2],โ€โ€)>>
<<End>>

Thanks. I tried this code:

<<Start: SELECT(Image_Row_Slice[ID],[ID]=โ€93f5fbc8โ€)>>
<<SWITCH([ImageSelect],
1,[Image1],
2,[Image2],
"")
>><<End>>

It didn't load any string or image into the email this time.

Here is a pic of the data preview in the slice.

Slice.png

Is the ImageSelect column a number or a text? If text, use "1", "2" etc. with the SWITCH()

Further to this, I imagine what's happening is that a slice doesn't store an image, only a reference to that image?

Hi Suvrutt, the issue is that the app needs to load one of 8 possible images in the email each time.

I need to determine a counter value like XXYYZZ from some user selections.

Then have a switch statement that for example if it's AABBCC then select Image1 but if it's AABBDD then select image2 and so on.

Things are a little more complicated by a need to display another value in the template, one of 5 letters. So for each of three questions in the form, there are two things to be selected for the template, an image and a Letter. The logic is like this (this is just the first three possible selections, out of eight):

 

S1 S1 S1
S1F1 S1F1 S1F2
S1F1P1 S1F1P2 S1F2P1
1 2 3
A B B

In the table, 1, 2 and 3 are numbers to select the correct image. A, B and B are values to display in text above the selected image.

I want to switch all this in the template so that from the string like "S1F1P2" it chooses Image2 and puts a B in some text. The switch won't show anything if the user hasn't selected enough options for the selector string.

The S1F1P1 string is stored in the column 'Counter' as a text field.

Images are stored in columns, image1 to image8.

The selection letter, A - E, is stored in the Letter column.

Top Labels in this Space