Unable to set a default image conditionally based on ThisItem value

Viewed 141

I'm using SQL Server IMAGE field type to store an image for a record. I set the Image attribute like so:

If(IsBlank(ThisItem.VisitorImage), 'full+pink+stroke+small+cropped (1)', ThisItem.VisitorImage)

If I set the image just to 'full+pink+stroke+small+cropped (1)' it works fine, so the image reference itself is fine. But none of my records have an IMAGE value yet, the database just shows null, and I want to display a default. How can I check for a blank/null IMAGE to display a default?

This also doesn't give me what I want.

Coalesce(ThisItem.VisitorImage, 'full+pink+stroke+small+cropped (1)')

1 Answers

Currently it is not possible to check, in Power Apps, if a SQL Server image is null (I'll create a bug with the product team to fix that). There are a couple of options you have:

  • Add a second image control with the 'full+pink+stroke+small+cropped (1)' image, and reorder it so that it lies behind the image control with the actual image; if there is no image in the row, then it won't show anything, and the backup image will be shown.
    • This may not work well if the image has transparent pixels
  • Add a new column in the SQL table, that tells whether it has an image or not. Something along the lines of ALTER TABLE <tableName> ADD HasVisitorImage AS IIF(VisitorImage IS NULL, 0, 1), and use this new column to choose whether to show the original or backup image: If(ThisItem.HasVisitorImage, ThisItem.VisitorImage, 'full+pink+stroke+small+cropped (1)')
Related