Jump to content
We've recently updated our Privacy Statement, available here ×
  • How to Add a Custom Function to Ad Hoc View Calculated Measure/Field Functions List


    asimkin
    • Features: Ad Hoc Version: v6.3 Product: JasperReports® Server

    Issue Description

    Customer would like to add a custom function to a list of functions available in Ad Hoc View Calculated Measure/Field mode .


    Resolution

    The Calculated Field or Calculated Measures dialog box allows you to create a calculated field or measure.

    TIBCO JasperReports® Server comes with a list of predefined functions, described in JasperReports Server User Guide:

    http://community.jaspersoft.com/documentation/tibco-jasperreports-server-user-guide/v630/calculated-fields-reference

    The list of functions defined in config file

    WEB-INFapplicationContext-el-operators.xml

    Let's review how to add ASCII PostgreSQL function which returns ASCII code of the first character of the argument, to the list.

    Solution tested with JasperReports Server v.6.3.0.

    https://www.postgresql.org/docs/9.4/static/functions-string.html

    1. Add ASCII function definition within list

    <util:list id="operatorDefinitionList">

     

            <bean parent="functionDef">
                <property name="name" value="ascii"/>
                <property name="javaType" value="java.lang.Integer"/>
                <property name="argumentTypes">
                    <list>
                        <value>#{ objectTypeMapper.checkType('String') }</value>
                    </list>
                </property>
                <property name="properties">
                    <map>
                        <!-- show in calc field dialog -->
                        <entry key="inAvailableFunctions" value="true"/>
                        <!-- always run in SQL -->
                        <entry key="alwaysInSQL" value="true"/>
                    </map>
                </property>
                <property name="inMemory" value="false"/>
            </bean>

     

    2. The next step is to add the custom function description available in Ad-Hoc designer when you click on the function.

    You can achieve it by adding description text into bundle files:

    WEB-INFbundlesadhoc_messages.properties

     

    under

     

    # Functions descriptions

     

    section, for example:

    adh.calculated.fields.function.description.ascii=Returns ASCII code of the first character of the argument

     

    3. After all the changes done, you should stop application server, clear temp folder and cache, start the server.

     

    Browser cache should be cleared as well.

     

    As a result, custom ASCII function is available in Ad Hoc Calculated Measure/Field mode:

    CustomCalcFunction.png.9c61aee5c58860c1235da77ec57db965.png


    Ref. Case 01444676

    UPD: How to Display Ad Hoc View Custom Function Arguments


    User Feedback

    Recommended Comments

    There are no comments to display.



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