Jump to content

Recommended Posts

Posted

Hello, I feel like I'm pulling teeth on the expressions for Jaspersoft. 

I'm trying to get a date to show on my report (ANY date), but when I preview it always shows null!

Here is an example of my expression.

DATEFORMAT(TODAY( ),"MMMMyyyy" )

 

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

I know how you feel lolz!

First off, I've never used the dateformat so let's scrap that part.

That leaves us with your TextField with the expression of TODAY( )

Click on the TextField and look at the properties window

there is a section on there called Pattern this is where you will format the date. you can type MMMMyyyy directly in the field since that should work but they also have some built in templates that you can check out too. To see the templates, there is a button to the right of the pattern field with ... on it

Hope this helps ya out and feel free to ask any follow up questions!

 

Posted

Thanks for the reply. The Pattern feature reduced my original expression (the one posted was just a test for this null issue).

 

I still get null on preview though.

 

This is what I did:

I created a variable.

In the variable I added my expression.

Then I created a text object in my group header.

I then added the variable into the text's expression.

I then previewed the document and I get 'Null'.

There shouldn't be a database issue with the above expression since it should take the date object from the computer's clock.

Posted

Jasper is picky, as I have come to learn. As soon as you said the Group Header, I know that was the issue. I'm no guru at Jasper, but I can tell you that Variables don't get calculated until the detail band (from what I have seen)

so you can do one of two things in this instance:

1. use a parameter instead of a variable. It can be used more than just for the user to enter a value.

2. change the evaluation time for the text field. The default evaluation time is Now. So in your case when when it got to the TextField, the value was still null. Thus for the group band, you can switch the eval time to Group[nameofthegroup]

 

but do not use Auto. From what I have read, it is not worth it and ends up using more resources

Posted

I tried every evaluation time and the result is always the same....null.

 

I'm trying this expression as I found it is the cause of my null problem but I can't find out why (part of my original expression, the previous one was only a test).

MONTH(IF($F{YearMonth} % 12 == 0, 12, $F{YearMonth} % 12))

The value of YearMonth is 24172

 

The REST operator works as I tested it without MONTH(OBJ) (returns 4). I need month to work, because the IF statement returns an object and I need it into an integer for the DATE(INT,INT,INT) expression.

Posted

Check if your variable's type is set to Date.  Text fields are String so try something like new SimpleDateFormat("yyyy/MM/dd").format($V{Variable_1})

 

    <variable name="Variable_1" class="java.util.Date">
        <initialValueExpression><![CDATA[new java.util.Date()]]></initialValueExpression>
    </variable>

 

            <textField pattern="">
                <reportElement x="340" y="49" width="100" height="20" uuid="e394a1cf-e490-4dc4-a528-b95596ee2479"/>
                <textFieldExpression><![CDATA[new SimpleDateFormat("yyyy/MM/dd").format($V{Variable_1})]]></textFieldExpression>
                <patternExpression><![CDATA[new SimpleDateFormat("yyyy/MM/dd").format($V{Variable_1})]]></patternExpression>
            </textField>

 

Posted

Hi,

To achieve this simply, 

1. You can set the expression of the Text feild where you are showing the Date as   -   new Date()

2. Now you see the properties for that particular text feild , there is a property called Pattern  

3. Click on the small button in the feild you will see a popup which would allow you to set various patterns for Percentage/Number/Date/Currency/Time .. etc 

4. You can then select Date and choose the format, MM/dd/yyyy

Now if  you run the report then you  can see the current date in desired format.

 

Cheers!!

 

Thanks,
Ankur Gupta

http://ankurthetechie.blogspot.in/
 

Posted

No change, still says null.

An update. This expression is no longer in my group 1 but now I decided to place it in the page header.

 

This is my expression:

new Date($F{YearMonth} / 12, MONTH(IF($F{YearMonth} % 12 == 0, 12, $F{YearMonth} % 12)), 1)

 

(weird how it will error if Date is set to DATE, when rest of the variables are in caps?)

Posted

Date in my table comes from a single integer, example: 24172

To get the year: the data value is divided by 12 (no decimal).

To get the month: the logic statement mods (or rest) the data value by 12. If the result is 0 then the returned logic value is 12, but if the result is not 0, the returned logic value is the data value mod (or rest) by 12 again.

For the day it is just set to 1.

 

I need this to be presented at the header of my first group.

The REST mathematical function works in Jasper as tested. but when it is added to the MONTH() it is where I think my problem is, as it just returns null (tested this by just a month expression).

 

Sorry for the confusion.

  • 5 years later...
Posted

Try to change Evaluation Time in text field properties.

If you use the variable, it can be that it's not evaluated at the time of displaying it.

From the tutorial "Variables and Expressions" (accesible from Help menu):

Evaluation Time.  The evaluation time is not an attribute of the variable but of the elements that can use variables in their expressions (like a Text Field) and define the "time" when the value of the variable should be read. A variable can potentially change value at every iteration, so a value read at one time may be different from the one obtained during another time. So for every element that can define an expression is possible to say when evaluate it. And since in the expression could be defined one or more variables this parameter also influences also when these variables are read. The possible values are:

Report: the value of the expression is evaluated ad the end of the report.

Page: the value of the expression is evaluated at the end of every page of the report.

Column: the value of the expression is evaluated at the end of each column (if the report is composed only of a column this is equivalent to Page).

Group : the value of the expression is evaluated after the break of the specified group. This option is visible only if at least one group is defined.

Band: the value of the expression is evaluated after the end of the band where the element with this evaluation time is placed. This is a very particular case, introduced to wait that the other elements in the band are completely created. The typical value of the variables are read at the start of the band, but for example suppose to have a subreport with an output parameter to print in the main report. To print this parameter it must be read when the subreport was already computed, so the value could be printed when the band is completely created, in this cases the Band evaluation time is necessary.

Auto: this is used when in the expression of the element there are more variables and fields, that need to be evaluated at different times. The variables are evaluated at a time corresponding to their Reset Type (see below for more information), instead the fields are always evaluated at time -now. This type is useful when report elements have expressions that combine values evaluated at different times (e.g. percentage out of a total).

Now: the value of the expression is evaluated after the read of every record, so at every iteration, this is the default behavior.

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