using the RIGHT function


Hi guys,

I'm very new to jaspersoft and especially java/groovy.

I can't seem to figure out how to properly use the RIGHT fucntion.


I have a field of which I only want the 6 most right characters to show up in my report.

I have tried the following :

RIGHT("$F{my field name}", 6)

but that returns some weird values: lue())


I've tried a lot of variations but I can't seem to get the syntax quite right. Any suggestions?



peter.boel's picture
Joined: Oct 11 2017 - 12:16pm
Last seen: 5 months 6 days ago

2 Answers:


RIGHT($F{ID},6) is working for me.

Those double quotes are messing up your result. Remove those double quotes.

I dont know why you have inserted those double quotes around the field value. 

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version using JasperReports Library version 6.4.1  -->
<jasperReport xmlns="" xmlns:xsi="" xsi:schemaLocation="" name="substring" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="53bd2dad-3301-4c64-954e-5b1ba2b00242">
    <property name="" value=""/>
        <![CDATA[select 'Hello987654321' as ID from dual]]>
    <field name="ID" class="java.lang.String"/>
        <band splitType="Stretch"/>
        <band height="30" splitType="Stretch">
                <reportElement x="0" y="0" width="100" height="30" uuid="c0ed5a35-c314-4258-be5f-ed2bbe7c4ce6"/>
                <reportElement x="180" y="0" width="100" height="30" uuid="f74dcaf2-4db0-4336-8761-92d69b0cfbf9"/>
                <text><![CDATA[Right 6 Values]]></text>
        <band height="30" splitType="Stretch">
                <reportElement x="0" y="0" width="100" height="30" uuid="337925dd-cccf-4896-b112-2259edcfb1c2"/>
                <reportElement x="180" y="0" width="100" height="30" uuid="d23925e9-4b17-46c4-921a-0b30ef834197"/>

reportdev's picture
Joined: Oct 12 2015 - 12:05pm
Last seen: 5 hours 5 min ago

What's RIGHT function? Try below:

($F{my field name}.length()>5)?$F{my field name}.substring( $F{my field name}.length() -  6):$F{my field name}

hozawa's picture
Joined: Apr 24 2010 - 4:31pm
Last seen: 1 day 6 hours ago