I've read all the entries related to how to use a user login in a report, but I'm missing something.
I've got 3.7 verson of jasperserver and the 3.6 version of iReports.
Most of the posts related to this say that you need to create 2 parameters. In iReports I've created a parameter LoggedInUser and set the Parameter Class to com.jaspersoft.jasperserver.api.metadata.user.domain.User and with a default value expression = Test
Then I create a second parameter UserID and give it a default value expression of $P{LoggedInUser}.getFullName()
The report has only one element - a text field to show the value of UserID. When compiled I get the error - ClassNotFoundException: com.jaspersoft.jasperserver.api.metadata.user.domain.User
Can anyone tell me what I'm doing wrong??
Here is the XML -
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="LoginNameTest" language="groovy" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false">
<defaultValueExpression><![CDATA[aaa]]></defaultValueExpression>
</parameter>
<parameter name="UserID" class="java.lang.String">
<defaultValueExpression><![CDATA[$P{LoggedInUser}.getFullName()]]></defaultValueExpression>
</parameter>
<background>
<band/>
</background>
<title>
<band height="79"/>
</title>
<pageHeader>
<band height="35"/>
</pageHeader>
<columnHeader>
<band height="61"/>
</columnHeader>
<detail>
<band height="125">
<textField>
<reportElement x="247" y="58" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$P{UserID}.toString()]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45"/>
</columnFooter>
<pageFooter>
<band height="54"/>
</pageFooter>
<summary>
<band height="42"/>
</summary>
</jasperReport>
14 Answers:
Hello,
The class com.jaspersoft.jasperserver.api.metadata.user.domain.User
exists only on the server so if you try to compile your report only with iReport this will not work.
Try to upload your report in the server and then run it from the server.
Hope this helps,
Guillaume
Post Edited by gautier at 01/10/2010 05:45
I've tried using it by itself setup as you describe and it come up null. I've gotten it to work where LoggedInUsername references a second parameter containing LoggedInUser.getUserName(), but at this time I can't get the parameter to work in a query.
I have only tried this with JasperServer 3.5.0, but the only thing you have to do, is in iReport to add a parameter of type String which is called "LoggedInUsername" (and that's the name reserved by JasperReport). This should correspond to manually adding the jrxml as listed in my last reply.
Come to think about it, the LoggedInUsername gives you the login name of the user currently logged in to the JasperServer, and not the attached Full Name field of this Jasper user account.
However, if the username (not the full name) would suffice, for me having the LoggedInUsername as String parameter replaced the need for having both the "LoggedInUser" parameter and the second parameter with default value $P{LoggedInUser}.getUsername().
I think perhaps "LoggedInUserFullName" exists as well. Also a String parameter that Jasper provides automatically without any input control.
Post Edited by msn at 01/11/2010 16:30
The parameters available are defined on this wiki page: http://jasperforge.org/plugins/mwiki/index.php/Jasperserver/Cascading_input_controls
@dknutson: I don't know why you are not getting the right value. It works in general for other folks.
Sherman
Jaspersoft
In the XML, add: <import value="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
And replace : <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false">
<defaultValueExpression><![CDATA[aaa]]></defaultValueExpression>
</parameter>
<parameter name="UserID" class="java.lang.String">
<defaultValueExpression><![CDATA[$P{LoggedInUser}.getFullName()]]></defaultValueExpression>
</parameter>
by:
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>
There isn't defaultValueExpression in this line.
Hello,
sory for my poor english ....
when I add
<import value="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>
I have the error " The selected Jrxml could not be parsed." when i load the JRXML using the Report Wizardof fasperserver 3.7.1
Is it possible to have a simple way to use "LoggedInUser" in que query ?
I do not undersand enough "http://jasperforge.org/plugins/mwiki/index.php/Jasperserver/Cascading_in...
Please help, tell me the way to do this easily ( "copy/paste")
sory for my poor english ....
when I add
<import value="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>
I have the error " The selected Jrxml could not be parsed." when i load the JRXML using the Report Wizardof fasperserver 3.7.1
Is it possible to have a simple way to use "LoggedInUser" in que query ?
I do not undersand enough "http://jasperforge.org/plugins/mwiki/index.php/Jasperserver/Cascading_in...
Please help, tell me the way to do this easily ( "copy/paste")
jpclerc,
We appreciate that you take the time and effort to post in English. Please do not worry about any mistakes in grammar or spelling.
You are replying to a thread that is relatively old. Please create a new thread.
Please add a few details. You say that you got the error when you added that parameter. Can you please confirm that you got no error and everything worked correctly before you added that parameter?
Have you looked at the report /reports/samples/SalesByMonth which ships with JasperServer Pro (now called JasperReports Server)? It has an example of using LoggedInUser. The example is just displaying the value in the report rather than using it in the SQL query... but it would be very easy to use it in the SQL query.
[Please don't respond in this thread, but create a new one instead.]
Regards,
Matt
So here is how my report looks, i have highlighted the code in red. It does not work on ireport 4.0(giving an error for java.lang.classnotfoundexception: com.jaspersoft.jasperserver.api.metadata.user.domain.User)
and on jasper server 4.0 it just says report is empty and no errors in the catalina.out
can you please let me know what i am missing?
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="userReport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<import value="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>
<parameter name="newUser" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{LoggedInUser}.getUsername()]]></defaultValueExpression>
</parameter>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="69" splitType="Stretch">
<staticText>
<reportElement x="129" y="21" width="100" height="20"/>
<textElement/>
<text><![CDATA[Trial report]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="26" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="13" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="116" y="29" width="173" height="36"/>
<textElement textAlignment="Center"/>
<textFieldExpression class="java.lang.String"><![CDATA[$P{newUser}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>