Jump to content

Use Formula field to display an Imagge


Recommended Posts

Hello - I have a field name with Data type Yes/No and in my tabular report, instead of displaying the value I want to show a Check mark imgae if the value is 'Yes' and an X mark if the value is NO. I was thinking of using a formula field. is this possible? Or is there any work around? Thank you.

Link to comment
Share on other sites

Hi NeoJS,

This can be possible using formula fields. However, the generated <img> element for the custom checkbox renders as text in tabular reports, due to an HTML encoding issue. The workaround is to use some script inside an HTML block to fix the encoding of the formula field result.

The entire solution for this forum post is as follows:

  1. Create a Yes/No field in the table if there's none yet. In this example, I created a Yes/No field called Status.
  2. Create a formula field that will generate the image tag based on the checkbox value. In this example, I created a formula field called Checkbox_Image.
  3. Put this formula inside the formula field:
    CASE WHEN [@field:Status] = 1
    THEN '<img src="FULL_URL_OF_CHECK_MARK" />'
    ELSE '<img src="FULL_URL_OF_X_MARK" />'
    END

    You cannot do something like <img src="[@field:My_Image_Field]"> inside the formula. That is, you cannot insert or use other fields as the image source URL.

  4. Then, on the tabular report, create an HTML block in the results page. Don't add the default Checkbox_Image field.
  5. Then, with the Source button enabled, paste this custom script there:
    <script>
        var imageLink = "[@field:Checkbox_Image]";
        imageLink = imageLink.replace(new RegExp("&lt;", 'gi'), "<");
        imageLink = imageLink.replace(new RegExp("&gt;", 'gi'), ">");
        imageLink = imageLink.replace(new RegExp("&quot;", 'gi'), '"');
        console.log(imageLink);
        document.write(imageLink);
    </script>

Hope this helps.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...