umair Posted April 22, 2008 Share Posted April 22, 2008 Is there any support for Global Variables in Jasper Reports? Like, if i want to retrieve the name of the user logged in..Is this possible? Link to comment Share on other sites More sharing options...
Gaby38 Posted April 23, 2008 Share Posted April 23, 2008 Try that : <parameter name="LoggedInUser" isForPrompting="true" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" and after in the definition of a Text Field : $P{LoggedInUser}.getFullName() (extract from French jasperserver forum: answer by Christopher André from Jaspersoft Corporation) Link to comment Share on other sites More sharing options...
umair Posted April 23, 2008 Author Share Posted April 23, 2008 What i need is to transfer the user name of the user logged in Jasper Server to the report made by Jasper Reports.How would i achieve that ? Link to comment Share on other sites More sharing options...
Gaby38 Posted April 24, 2008 Share Posted April 24, 2008 In iReport, you edit your jrxml code. In the left frame, you add a parameter with name "LoggedInUser", you check the "Use as prompt" box and you put "com.jaspersoft.jasperserver.api.metadata.user.domain.User" in the combo parameter type (perhaps a problem with a class not found but don't care) Then you add in your report a textField and you define its expression definition as "$P{LoggedInUser}.getFullName()" When you run the report, the text field contains the logged user name. Link to comment Share on other sites More sharing options...
Gaby38 Posted April 24, 2008 Share Posted April 24, 2008 In iReport, you edit your jrxml code. In the left frame, you add a parameter with name "LoggedInUser", you check the "Use as prompt" box and you put "com.jaspersoft.jasperserver.api.metadata.user.domain.User" in the combo parameter type (perhaps a problem with a class not found but don't care) Then you add in your report a textField and you define its expression definition as "$P{LoggedInUser}.getFullName()" When you run the report, the text field contains the logged user name. Link to comment Share on other sites More sharing options...
umair Posted April 24, 2008 Author Share Posted April 24, 2008 Heres what i did,View->Parameters->New ParameterName: LoggedInUserClassType: StringUseAsPrompt: checked Applied a Text Field with expression definition as "$P{LoggedInUser}.getFullName()".Saved the report, uploaded the jrxml file and ran to see the following errors: com.jaspersoft.jasperserver.api.JSExceptionWrapper: Errors were encountered when compiling report expressions class file: 1. The method getFullName() is undefined for the type String value = (java.lang.String)(((java.lang.String)parameter_LoggedInUser.getValue()).getFullName());//$JR_EXPR_ID=12$ <---------> 2. The method getFullName() is undefined for the type String value = (java.lang.String)(((java.lang.String)parameter_LoggedInUser.getValue()).getFullName());//$JR_EXPR_ID=12$ <---------> 3. The method getFullName() is undefined for the type String value = (java.lang.String)(((java.lang.String)parameter_LoggedInUser.getValue()).getFullName());//$JR_EXPR_ID=12$ <---------> 3 errors com.jaspersoft.jasperserver.api.JSExceptionWrapper: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:1. The method getFullName() is undefined for the type String value = (java.lang.String)(((java.lang.String)parameter_LoggedInUser.getValue()).getFullName());//$JR_EXPR_ID=12$ <--------->2. The method getFullName() is undefined for the type String value = (java.lang.String)(((java.lang.String)parameter_LoggedInUser.getValue()).getFullName());//$JR_EXPR_ID=12$ <--------->3. The method getFullName() is undefined for the type String value = (java.lang.String)(((java.lang.String)parameter_LoggedInUser.getValue()).getFullName());//$JR_EXPR_ID=12$ <---------> Link to comment Share on other sites More sharing options...
Gaby38 Posted April 25, 2008 Share Posted April 25, 2008 Umair,I think your problem comes from the fact you defined the parameter type as "string" and not as "com.jaspersoft.jasperserver.api.metadata.user.domain.User" as said. This is not in the combo list : you must enter it by overwriting in the combo.In my case, under iReport this class is not defined so you got a "Problem". But it is defined in jasperserver and if you run the report from jasperserver there is no problem. I tested on one report before posting my reply. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now