Jump to content
JasperReports Library 7.0 is now available ×

Query filtered by LoggedInUser.getUsername()


robertpopa22

Recommended Posts

Hi,

 

We have a lot of users and we need to create only one report! We need to use the LoggedInUser.getUsername() or LoggedInUser.getFullName() to filter out records, so that the user can see his (an only his) data in the report.

 

We have tried to use (from the posts existing here) this query:

 

Code:

 

and we have declared the parameter like this:

size=300] size=323]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/parameter-e7b4ffca05cf8643b7c2d7a18ad396b4.JPG

 

When we publish the report on the server we receive this error:

com.jaspersoft.jasperserver.api.JSExceptionWrapper: net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. Parameter type not supported in query : LoggedInUser class com.jaspersoft.jasperserver.api.metadata.user.domain.User

 

We have studied the SalesByMonths example, but there is a different approach to LoggedInUser.

 

Please help us with an example or tutorial on how to do this in iReports and publish it on the server.

 

Thank You!

P.S. If there is another approach to this matter please show us! :woohoo:

Link to comment
Share on other sites

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

"WHERE users.name = '$P{LoggedInUser}.getFullName()'" will not work, you'll have to do something like this:

  • Define a new parameter named LoggedInUserName, and set it's default value expression to $P{LoggedInUser}.getFullName().

Use $P{LoggedInUserName} in the query (note that you don't need to use quotes around the parameter placeholder).[/ul]

 

HTH,

Lucian

Link to comment
Share on other sites

Thanks, but it doesn't work yet...

 

I have created a 1st parameter $P{LoggedInUser} from class com.jaspersoft.jasperserver.api.metadata.user.domain.User with no default value (also tried prompt and no prompt)

 

Then I created the 2nd parameter $P{LoggedInUserName} of class java.lang.String with the default value of $P{LoggedInUser}.getFullName() (also tried prompt and no prompt)

 

The query was:

SELECT

details.`Detail` AS details_Detail,

users.`name` AS users_name,

users.`db` AS users_db

FROM

`details` details LEFT OUTER JOIN `users` users ON details.`idUser` = users.`idUser`

WHERE

users.name = $P{LoggedInUserName}

 

*Note! When I used the default value of "Name1", the report printed out ok, so the query is good.

 

In the SQL Query log we have:

SELECT

details.`Detail` AS details_Detail,

users.`name` AS users_name,

users.`db` AS users_db

FROM

`details` details LEFT OUTER JOIN `users` users ON details.`idUser` = users.`idUser`

WHERE

users.name = NULL

 

Please help us to understand what are we doing wrong ... :)

Link to comment
Share on other sites

$P{LoggedInUserName}.getFullName() ? Perhaps you reffered to $P{LoggedInUser}.getFullName() ...

 

Yes, $P{LoggedInUser}.getFullName() returns as String the name of the user... Everything ok here, in the text field.

 

Perhaps there are some differences in the query parser?

Link to comment
Share on other sites

Yes, I meant $P{LoggedInUser}.getFullName(). You could also try to show $P{LoggedInUserName} in a text field..

 

I don't understand why LoggedInUserName's default value expression doesn't work. Could you post your JRXML so that we'd be able to replicate the issue? How are you running the report?

Link to comment
Share on other sites

You are using $P{LoggedInUser} in the query, and not $P{LoggedInUsername} as you should. Fix this and see whether it works.

 

By the way, is it possible to send a file/image to the forum? until now I only could post links to my website.

 

It should be possible, aren't the image and file attachment controls working?

 

Regards,

Lucian

Link to comment
Share on other sites

Hello,

 

Just to say that I already have a report like the one of Robert which runs a query on the meta database and I filter with the name of the user.

 

I did exactly as Lucian said, that is :

- create a 2nd parameter "$P{FullUserName}" initialized by defaut with "$P{LoggedInUser}.getFullName()"

- and in my query I have :

"where jasperserver.JIUser.fullname=$P{FullUserName}"

 

and it works fine.

Link to comment
Share on other sites

Hello,

 

Just to say that I already have a report like the one of Robert which runs a query on the meta database and I filter with the name of the user.

 

I did exactly as Lucian said, that is :

- create a 2nd parameter "$P{FullUserName}" initialized by defaut with "$P{LoggedInUser}.getFullName()"

- and in my query I have :

"where jasperserver.JIUser.fullname=$P{FullUserName}"

 

and it works fine.

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...

Is it possible to pass a parameter into the query of a input control (which is multi-select list). So thr list contents will differ depending on the value of the parameter, e.g. $P{LoggedInUserUsername}. I'm able to display the correct value of the username, but looks like the input control's query not receiving it properly, and the content of the list is empty.

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 months later...

As an appendum to the original post , in case anyone else is trying this, the initial parameter of type class com.jaspersoft.jasperserver.api.metadata.user.domain.User *has* to be named LoggedInUser or a null value will be returned from any method called on it.

 

Strange.

Link to comment
Share on other sites

  • 5 months later...

Sorry, i hadn't create LoggeInUser parameter but only the second parameter that use it.

I named the second parameter USERNAME.

I have discover that if you put USERNAME, before LoggeInUser, it's impossible for it to read LoggeInUser parameter.

I think that the order of parameters is the order of instantiation. When I read USERNAME, LoggeInUser wasn't instantiated yet.

Read the correct code here below:

Code:


Post Edited by helyair at 11/06/2009 10:05
Link to comment
Share on other sites

Hi,

 - defined new parameter and named username, and set Parameter Class Tyape: java.lang.String, and set Use as aPrompt:True

and set Default Value Expression: $P{LoggedInUser}.getFullName(), then click OK.

 - use '$P!{username}' in query.  where user.name = '$P!{username}'

it should work, I tried it. :)

 

Samer

Link to comment
Share on other sites

  • 9 months later...

swood
Wrote:

What you are after is what we call "cascading input controls". There is no solution for this right now, but we are looking to package up some extensions to JasperServer you can add to do this.

 

Sherman

Jaspersoft

 

 

Is there any news?...

I have tried to use $P{LoggedInUsername} on a input control query.

Query runs correctly, but every browser (Safari, Firefox, IE) gives same error. See image below.

Update: this error occurs only on JS 3.7, it doesn't occur on JS 3.5.

Post Edited by helyair at 08/30/2010 13:16



Post Edited by helyair at 08/30/2010 13:38



Post Edited by helyair at 08/30/2010 16:01
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...