Geert.Boeve Posted August 11, 2015 Share Posted August 11, 2015 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 More sharing options...
srang Posted August 11, 2015 Share Posted August 11, 2015 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 More sharing options...
srang Posted August 11, 2015 Share Posted August 11, 2015 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 More sharing options...
Geert.Boeve Posted August 13, 2015 Author Share Posted August 13, 2015 Thanks for the tip. I used the standard LoggedInUser in JasperStudio with the wrong class com.jaspersoft.jasperserver.api.metadata.user.domain.client.UserImpl. 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