Jump to content
We've recently updated our Privacy Statement, available here ×

Using logged in user id - Last Chance for me


dknutson

Recommended Posts

Folks, I'm completing stuck.  I'm using the parameter $P{LoggedInUsername} in a very simple report.  I've actually tried this both ways - once using only $P{LoggedInUsername} and also by using the 2 parameters $P{LoggedInUser} and $P{LoggedInUsername}.  Both fail in the same way.

I've included the xml for both reports.  Here is what happens.  I create report1 and it works!  It shows the user login name and returns the correct values from the query.

Then I edit the report to add another field to the query.  The report stops working because it now returns a NULL for the login name.  It's not the query as the report does the same thing even if I hardcode the login name.

HELP!

 


Report 1 - the working report

<?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="test2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
 <parameter name="LoggedInUserName" class="java.lang.String">
  <defaultValueExpression><![CDATA["DMKtest"]]></defaultValueExpression>
 </parameter>
 <parameter name="LoggedInUsername" class="java.lang.String"/>
 <queryString>
  <![CDATA[select sd.storeid
from bkdata.dbo.storedata sd
inner join jasperreports.dbo.selectstores ss
  on sd.storeid = ss.storeid
and ss.userid = $P{LoggedInUsername}]]>
 </queryString>
 <field name="storeid" class="java.lang.String">
  <fieldDescription><![CDATA[]]></fieldDescription>
 </field>
 <background>
  <band/>
 </background>
 <title>
  <band height="19"/>
 </title>
 <pageHeader>
  <band height="14"/>
 </pageHeader>
 <columnHeader>
  <band height="61">
   <textField>
    <reportElement x="51" y="21" width="100" height="20"/>
    <textElement/>
    <textFieldExpression class="java.lang.String"><![CDATA[$P{LoggedInUsername}]]></textFieldExpression>
   </textField>
  </band>
 </columnHeader>
 <detail>
  <band height="25">
   <textField>
    <reportElement x="51" y="0" width="100" height="20"/>
    <textElement/>
    <textFieldExpression class="java.lang.String"><![CDATA[$F{storeid}]]></textFieldExpression>
   </textField>
  </band>
 </detail>
 <columnFooter>
  <band height="45"/>
 </columnFooter>
 <pageFooter>
  <band height="54"/>
 </pageFooter>
 <summary>
  <band height="42"/>
 </summary>
</jasperReport>
 

 


The bad report -

<?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="test3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
 <parameter name="LoggedInUserName" class="java.lang.String">
  <defaultValueExpression><![CDATA["DMKtest"]]></defaultValueExpression>
 </parameter>
 <parameter name="LoggedInUsername" class="java.lang.String">
  <defaultValueExpression><![CDATA[]]></defaultValueExpression>
 </parameter>
 <queryString>
  <![CDATA[select sd.district, sd.storeid
from bkdata.dbo.storedata sd
inner join jasperreports.dbo.selectstores ss
  on sd.storeid = ss.storeid
and ss.userid = $P{LoggedInUsername}]]>
 </queryString>
 <field name="district" class="java.lang.String">
  <fieldDescription><![CDATA[]]></fieldDescription>
 </field>
 <field name="storeid" class="java.lang.String">
  <fieldDescription><![CDATA[]]></fieldDescription>
 </field>
 <background>
  <band/>
 </background>
 <title>
  <band height="19"/>
 </title>
 <pageHeader>
  <band height="14"/>
 </pageHeader>
 <columnHeader>
  <band height="61">
   <textField>
    <reportElement x="51" y="21" width="100" height="20"/>
    <textElement/>
    <textFieldExpression class="java.lang.String"><![CDATA[$P{LoggedInUsername}]]></textFieldExpression>
   </textField>
  </band>
 </columnHeader>
 <detail>
  <band height="25">
   <textField>
    <reportElement x="51" y="0" width="100" height="20"/>
    <textElement/>
    <textFieldExpression class="java.lang.String"><![CDATA[$F{storeid}]]></textFieldExpression>
   </textField>
   <textField>
    <reportElement x="174" y="0" width="100" height="20"/>
    <textElement/>
    <textFieldExpression class="java.lang.String"><![CDATA[$F{district}]]></textFieldExpression>
   </textField>
  </band>
 </detail>
 <columnFooter>
  <band height="45"/>
 </columnFooter>
 <pageFooter>
  <band height="54"/>
 </pageFooter>
 <summary>
  <band height="42"/>
 </summary>
</jasperReport>
 

 



Post Edited by dknutson at 01/17/2010 17:55
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Amazing what a new day will bring.  After sleeping on it I found what was causing the problem.  When you set a default for LoggedInUsername, the following entry is created in XML -

<parameter name="LoggedInUsername" class="java.lang.String" isForPrompting="false">
  <defaultValueExpression><![CDATA['TEST"]]></defaultValueExpression>
 </parameter>

 

Now, if I delete the default value of "TEST",  iReports still leaves the string

<defaultValueExpression><![CDATA[]]></defaultValueExpression>

Jasperserver is seeing this as being a default value set to NULL and uses that instead of the login name.  If I delete this string, then everything works.

 

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...