$P{LoggedInUsername} works in a text box, not in the query.

I have a simple report which displays an total for month to date.

The footer of this report does display the user who is logged into JasperReports Server Pro.

This was completed by creating the parameter:

LoggedInUsername - Class = java.lang.String - Is For Prompting = False


SELECT count FROM table WHERE CreationDate > First_Day (Current_Date) AND table.user = '$P!{LoggedInUsername}'

If I hard code a value the report works fine.

If I attempt to use the paramter LoggedInUsername, it fails.

I have tried surrounding the parameter in single quotes .... and without the single quotes.

I have tried placing an exclamation mark between the P and open Brace .... and without the exclamation mark.

I have tried with all the variations of the above I can think of.

the cvurrent and most common error is   : Query parameter not foundd: LoggedInUsername ----net.sf.jasperreports.engine.design.JRDesignQuery@xxxxxxx

In the Public - Library - Input Control resource editor I have defined LoggedInUsername as an Input Control || Single Value || Local Resource = DataType = Text


Any suggestions are appreciated.



mike.atkinson's picture
Joined: Aug 25 2020 - 5:26am
Last seen: 6 months 4 weeks ago

3 Answers:

I got it.

Create a Parameter in the Main Dataset

Create a Parameter in the Table SubDataset

Link the two parameters together in the Table Dataset Properties.


mike.atkinson's picture
Joined: Aug 25 2020 - 5:26am
Last seen: 6 months 4 weeks ago

It's a curious phenomenon.
For debugging purposes, why don't you try placing a temporary text field?
For the text feed expression, specify $P{LoggedInUsername}.
Check to see if the 'value displayed' matches the 'value you specified in the fixed value'.
You may be able to find 'differences in uppercase and lowercase letters' or 'differences with and without extra spaces'.

I tried with the following SQL and it worked as expected.
The database I am using is MySQL, so the syntax is a little different.

WHERE CreationDate > date_format(curdate(), "%Y-%m-01")
AND TABLE.user =  $P{LoggedInUsername}

- test data

- Report Design

- Report Display Results

yama818's picture
Joined: Aug 17 2018 - 3:48pm
Last seen: 1 month 2 weeks ago

yama818 ... thanks.

I have a text box on the report, and it does populate with my username. Case sensitivity on the parameter is important.

The challenge continues to be the query. My current status is that I have gotten past the error, but it still doesn't seem to be populating the correct result.

To get past the errors, I had to do two things:

  • A - Create the Parameter in the Main Body of the report.
  • B - And the add that parameter to the Table Dataset.

This eliminates the error when previewing. But it still is not populating the correct answer.

So, I continue to work on it. Again ... Thanks,

mike.atkinson's picture
Joined: Aug 25 2020 - 5:26am
Last seen: 6 months 4 weeks ago