Parameter2 based on Parameter1

0

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.

 

danoldenkamp@gmail.com's picture
Joined: Aug 29 2018 - 11:12am
Last seen: 1 day 7 hours ago

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. 

danoldenkamp@gmail.com - 5 months 1 week ago

1 Answer:

0

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

C-Box's picture
2122
Joined: Jul 19 2006 - 5:58pm
Last seen: 2 days 16 hours ago
Feedback
randomness