How to get LoggedInUser parameter from Input Controls

0

Hi,

So we are trying to set up input controls for our reports that would allow up to get the LoggedInUser's user attributes. To give a little bit of context, we are using external authentication, and the user attributes we are using corrsepond to a collection of ids that we can add to join/where clauses in the input control queries. We also custom utility class that allows us to parse the user attributes and transform them into an sql-safe list (for in statements and whatnot, because the raw attribute value is just a comma seperated string of ids).

 

What I would expect I'd need for this to work is something like this in the jrxml:

    <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>
    <parameter name="userLinkedBriefIds" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA[com.jaspersoft.smartbrief.util.UserParamUtil.getAttributeSQLValue($P{LoggedInUser}.getAttributes(), "briefId")]]></defaultValueExpression>
    </parameter>

Then that I would be able to access that userLinkedBriefIds from the input control query like:

select briefid, brief_name from alchemy.dbo.brief b
where b.activestatus like 'A%'
and (b.briefname_alias = '' OR b.briefname_alias is null)
and (b.parentid is null)
and b.briefid in $P!{userLinkedBriefIds}
order by b.brief_name asc

But, the input control doesnt even load in the report and we get an error in the logs with a stacktrace like this (abbreviated since its pretty long)

2013-10-01 14:31:17,466 ERROR GenericExceptionMapper,http-8080-5:42 - Unexpected error occurs
net.sf.jasperreports.engine.JRRuntimeException: Parameter "userLinkedBriefIds" does not exist.
        at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.checkParameter(JRAbstractQueryExecuter.java:787)
        at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.appendParameterClauseChunk(JRAbstractQueryExecute
r.java:464)
        at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.appendQueryChunk(JRAbstractQueryExecuter.java:373
)
        at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.parseQuery(JRAbstractQueryExecuter.java:358)
        at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.<init>(JRJdbcQueryExecuter.java:139)
        at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.<init>(JRJdbcQueryExecuter.java:147)
        at com.jaspersoft.jasperserver.api.engine.jasperreports.util.JRTimezoneJdbcQueryExecuter.<init>(JRTimezoneJdbc
QueryExecuter.java:127)
        at com.jaspersoft.commons.util.JSControlledJdbcQueryExecuter.<init>(JSControlledJdbcQueryExecuter.java:65)
        at com.jaspersoft.commons.util.JSControlledJdbcQueryExecuterFactory.createQueryExecuter(JSControlledJdbcQueryE
xecuterFactory.java:26)
        at net.sf.jasperreports.engine.query.AbstractQueryExecuterFactory.createQueryExecuter(AbstractQueryExecuterFac
tory.java:49)
        at com.jaspersoft.jasperserver.api.engine.jasperreports.util.JRQueryExecuterAdapter.executeQuery(JRQueryExecut
erAdapter.java:92)
        at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.executeQuery(EngineServ
iceImpl.java:2117)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
 

I'm able to get the value of the report parameter from the actual report (by either putting it into a text field or by actually using it in the report query), but from the input control its just not working.

 

Has anyone tried anything similiar and had success?

kfreisen's picture
Joined: Jul 15 2013 - 7:34am
Last seen: 2 months 1 week ago

1 Answer:

0

Hello Dear,

Logged in user name can be passed to query based input control by using the built-in parameter $P{LoggedInUsername}.

Just put it  $P{LoggedInUsername} ...instead of

$P!{userLinkedBriefIds}

This should work . Good luck.

 

sourabh.g's picture
Joined: Jul 20 2013 - 12:01am
Last seen: 8 months 1 week ago
Feedback
randomness