Jump to content
Changes to the Jaspersoft community edition download ×

Parameter2 based on Parameter1


Recommended Posts

Hello and thanks for all your past help.

The nature of a query is if a user chooses one parameter, then I have to set a couple different where conditions.  (normally I would just use a long string, but also am need to use the parameter in the group by)

Long story short.

If I could have one user parameter and then set another parameter with a condition.  

 

Parameter1:  "invoice" or "sales order"

Parameter2: if parameter1 is "invoice" then 'I' if it's "sales order" then "O"

Source:

  <parameter name="Parameter2" class="java.lang.String" evaluationTime="Late">
        <defaultValueExpression><![CDATA[($P{Parameter1}.equals("invoice") ? "I" :
($P{Parameter1}.equals("sales order") ? "O" :"")    
)]]></defaultValueExpression>

 

Maybe its the evaluation time, but I can't get this to display anything other than null.

Maybe a variable would be better?  Would rather not display Parameter2 to the user.

 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi Dan, 

I also used  let's call "hidden" calculated parameters for the (main) query that depends on the original interactive parameters given by the user in some customer reports some years ago.

When I remember right, you must use the exclamation mark somewhere "!" for the calculated parameter.... so that not the "$P{Parameter1}" as string is evaluated  in the expression but it's actual content instead.

Also the "hidden" (not askUser) parameter must be in the parameter order AFTER the interactive user-parameter(s)... otherwise it would always be null.

So try to use  $P!{Parameter2} in your query.   (can't look for a real sample, as I doesn't have access to that reports any more, so I'm not 100% sure ...could also be the way around for parameter1 - just play around with both ways )

hth + regards

C-Box

Link to comment
Share on other sites

Hmm, 

regarding setting the Expression or Initial Value Expression to that of another parameter higher in the published parameter list,

$P!{Parameter} is not valid in the expression editor.

!${Parameter}  evaluates to true regardless of the parameter.

 

Tried it, a number of ways with variables / parameters.  

 

(This is why I never get rid of anything that I write for other people.  You never know when it may be a good reference)

:)

 

If I could evaluate the 1st parameter within a dataset query, that could be another option,

($P{Parameter}.equals("Op

tion1") ? "InsertSQL" :
($P{Parameter}.equals("Option2") ? "OtherSQL" :"" 
))

 

but of course the query evaluation doesn't like that. 

Maybe someone else has been succesful with this. 

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