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

Role name in jasper


sup03

Recommended Posts

Hi,

I need to filter data in the report based in logged in user's role. I followed the link http://jasperetl.org/plugins/espforum/view.php?group_id=112&forumid=102&topicid=67746

This is the jrxml  <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>
 <parameter name="LoggedInUserRole" class="java.util.Collection" isForPrompting="false">
  <defaultValueExpression><![CDATA[$P{LoggedInUser}.getRoles()]]></defaultValueExpression>
 </parameter>
 <parameter name="LoggedInUserRoleString" class="java.util.Collection" isForPrompting="false">
  <defaultValueExpression><![CDATA[$P{LoggedInUserRole}.toString()]]></defaultValueExpression>
 </parameter>
 <queryString>
  <![CDATA[select * from report_roles where  $X{IN, role_name, LoggedInUserRoleString}]]>
 </queryString>

This throws an error when deployed on jasperserver3.7. Please let me know if anyone has implemented the same.

 

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

you can simply use the parameter -> LoggedInUserRoles [ in built parameter] in query

select * from report_roles where  $X{IN, role_name, LoggedInUserRoles}

there is no need to extarct it to string first ..i.e. no need of using LoggedInUserRoleString ..In Built Parameter = LoggedInUserRoles works perfect ..

thanks

Ramnik Kaur

Senior QA Engineer

Link to comment
Share on other sites

  • 1 year later...

Hello,

what ramnik wrote is true.
Something important to take into consideration though:

"When defining these parameters in a report, don’t use a defaultValueExpression element. Due to a limitation in
JasperServer, these parameters are null when a defaultValueExpression is provided."


And that could be difficult to see if you are not working directly into the JRXML file:
once you have defined a default expression and deleted it (let that field empty in iReport), the entry

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

within that Parameter (LoggedInUserRoles) stays in the JRXML file forever (causing LoggedInUserRoles to be null !) unless you deleted it manually!
 

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