Setting Image Path using Parameter

Hello, 

 

I have reports set up to show data based on LoggedInUsername. I would like to include the conpamies image as well. The image needs to change based on the LoggedInUsername. How can I achieve this?

 

I though maybe I could upload images to the Server in the Image folder and then pass in a Paramater that way but it is not working for me. 

 

example /images/$P{LoggedInUsername}

r00's picture
r00
3
Joined: May 12 2021 - 12:01pm
Last seen: 2 years 1 day ago

1 Answer:

I'm assuming you're referring to the person actively logged into jasper server, and that there is a directory (or image name, or some text string) for each of those unique users/companies located on jasper server. If so, you're on the right path you can do this. When you define the path location to the image in the report, you need to tack on the image file extension. So if the user is Joe_User, and the file is located in jasper server as 

/images/Joe_User.png, you'd want to define the image url in the report like "/images/"+$P{LoggedInUsername}+".png"

I don't know how many users/companies etc you need to support, but this approach won't scale well. If you need a scalable solution, if you can derive the company name from the report query, then you can specify the image location using a variable rather than a parameter. This is a fairly common problem with multiple possible solutions. So you can do it exactly as you describe, but that solution won't scale well - if that matters.

Here's a list of common user attributes available 'out of the box' for logged in users, you can also create your own custom user attributes. https://community.jaspersoft.com/wiki/built-parameters-logged-user

 

darth_fader's picture
Joined: Mar 7 2010 - 9:45pm
Last seen: 6 hours 30 min ago
Feedback
randomness