3

I want to restrict the values in multi-select input control in my report based on the logged in user. For example, If manager logs in, he can see the list of all employees in the multi-select list. If an employee logs in, he will see only his name on the list. What is the best way to do that?

saurabh730
  • 113
  • 2
  • 12

2 Answers2

3

Try to add a new parameter "LoggedInUser" which will give you the LoggedIn User ID and then you can pass this parameter in where clause of the query

<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
<parameter name="FullUserName" class="java.lang.String">
    <defaultValueExpression><![CDATA[$P{LoggedInUser}.getFullName()]]></defaultValueExpression>
</parameter>
Sharad
  • 3,562
  • 6
  • 37
  • 59
  • Thanks for your suggestion.I have now created the LoggedInUser parameter. I have also created another parameter FullUserName of type string with default value $P{LoggedInUser}.getFullName(). But when I try to print it on report, it displays null. Am I missing something? – saurabh730 Nov 20 '13 at 06:05
  • What you can do just copy the above XML code of parameters and directly copy in xml code of the JRXML. – Sharad Nov 20 '13 at 06:10
0

Most likely you will need to do some recursive sql with ID being your User name

SELECT t1.id, 
       t1.parent_id, 
       t1.name,
       t2.name AS parent_name,
       t2.id AS parent_id
  FROM tbl t1
  LEFT JOIN tbl t2 ON t2.id = t1.parent_id 
 START WITH t1.id = $P{LoggedInUsername} 
CONNECT BY PRIOR t1.id = t1.parent_id
Mike Noland
  • 505
  • 3
  • 10