How can i perform null handing for Photos while fetching from Database

Hi,

I want to perform the null handling for the photos which are not available for a particular user.

Here I'm fetching an user details from a database, I intentionally made that photo field to null for a particular user then I'm getting the following error

ERROR:

Interface Definition: Expression evaluation error at function a!imageField [line 37]: The image at index 1 in an image gallery component [label=“Photo”] has an invalid value for “document”. “document” must not be null.

Code:

a!imageField(

label: "Photo",

labelPosition: "ADJACENT",
images: a!documentImage(
document: local!getemp.photo,
)

my requirement is, If the photo field is null for a particular user it should display empty and if the user is having a photo then it should display picture (This is not an user photo, this is a dummy photo which i uploaded from another interface to table)

  • Hi Harish,

    As per my knowledge you can not display empty image field. You can do the workaround for it.

    Define one default photo in your database and when the photo for the user is null display that default photo.

  • Hi Harish,

    I think I've got a treat for you. You can get the Appian default image document id by using the code sample below.

    a!richTextDisplayField(
      value: tostring(
        a!userImage(
          user: "userWithoutImage"
        ).document
      )
    )

    Replace the 'userWithoutImage' with any user on your environment that doesn't have a photo. 
    It will give you the default image document id for the current environment. Now can store this id in a constant and use it with an if statement. 
    Where if the id from the database is null, you can pass the constant.

    But this won't work after the application is deployed on a new environment. So another thing you can do is to download this default document image using documentDownloadLink() function and upload it as a new document on Appian and map that document in a constant. That's a more stable way of doing it.

    Thanks,
    Harshit

 Discussion posts and replies are publicly visible