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

$P{LoggedInUser}.getAttributes() returns null


Geert.Boeve

Recommended Posts

I need to create JasperReports with user specific attributes to be used on JasperServer.

But the parameters $P{LoggedInUser}.getAttributes() and $P{LoggedInUserAttributes} always return null.

Do I need to perform some initialization or are these parameters not available on the community version of JasperServer?

We use at the moment JasperServer version 6.0.1

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I'm not sure of their availability in community vs commercial editions but I did come across a few problems getting them to work the way you'd expect. First of all I couldn't get $p{LoggedInUser} to resolve within jasperstudio but once it was uploaded to the server it worked fine. Second, I had to split up getting a property into multiple steps that had to execute in a certain order. Here is a snippet of how I've gotten an attribute from a user in the past.

    <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>    <parameter name="OrgAttr" class="com.jaspersoft.jasperserver.api.metadata.user.domain.ProfileAttribute" isForPrompting="false">        <defaultValueExpression><![CDATA[(com.jaspersoft.jasperserver.api.metadata.user.domain.ProfileAttribute)$P{LoggedInUser}.getAttributes().get(0)]]></defaultValueExpression>    </parameter>    <parameter name="OrgID" class="java.lang.Integer" isForPrompting="false">        <defaultValueExpression><![CDATA[integer.valueOf($P{OrgAttr}.getAttrValue())]]></defaultValueExpression>    </parameter>[/code]

Then you can use $P{OrgID} as the actual attribute either within the report query or passed as a param to a subdataset. Hopefully this helps!

Link to comment
Share on other sites

Oops posted that as a comment meant for it to be an answer!

I'm not sure of their availability in community vs commercial editions but I did come across a few problems getting them to work the way you'd expect. First of all I couldn't get $p{LoggedInUser} to resolve within jasperstudio but once it was uploaded to the server it worked fine. Second, I had to split up getting a property into multiple steps that had to execute in a certain order. Here is a snippet of how I've gotten an attribute from a user in the past.

    <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>    <parameter name="OrgAttr" class="com.jaspersoft.jasperserver.api.metadata.user.domain.ProfileAttribute" isForPrompting="false">        <defaultValueExpression><![CDATA[(com.jaspersoft.jasperserver.api.metadata.user.domain.ProfileAttribute)$P{LoggedInUser}.getAttributes().get(0)]]></defaultValueExpression>    </parameter>    <parameter name="OrgID" class="java.lang.Integer" isForPrompting="false">        <defaultValueExpression><![CDATA[integer.valueOf($P{OrgAttr}.getAttrValue())]]></defaultValueExpression>    </parameter>[/code]

Then you can use $P{OrgID} as the actual attribute either within the report query or passed as a param to a subdataset. Hopefully this helps!

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