Jump to content
Changes to the Jaspersoft community edition download ×
  • CVC passing parameters into external Javascript files


    effrenchtibco.com
    • Features: Charts Version: v7.1 Product: Jaspersoft® Studio

    This page explains how to pass and use data in TIBCO Jaspersoft® Studio CVC JavaScript files. This is outlined here: https://community.jaspersoft.com/documentation/tibco-jaspersoft-studio-user-guide/v71/custom-visualization-component-0

    By data, we mean anything in a report such Fields, Parameters, Variables, ect..

    This article uses samples from the Custom Visualization Component article: https://community.jaspersoft.com/wiki/custom-visualization-component-v60x-how-run-samples

    Please refer to that article to understand how to run CVC components in general.

    Define data to pass into JavaScript

    In Studio, select the CVC properties > Data tab, then click the add button in the bottom right panel to define the data items you want to pass into your JavaScript.

    image1.png.c475f597253f4d8bbe89a55e88188e12.png

    On the next screen click on "Add" again and fill in the below values.  

    image2.png.dce47e4bce1726d4ba9bebd82a72382d.png

    The "Property Name" will be what you will call in your JavaScript to get the values.  "Property Value" will be the value you are passing from the report. 

    Make sure to click the "Use Expression" checkbox. You can keep adding values until you have passed everything. The result should look like this:

    image3.png.307fd4f731e2651e0c83111f6db2767f.png

    Using data within the JavaScript code

    Within your program, start by making sure you have a "instanceData" parameter set in your function. 

    return function (instanceData)

    Then create a variable to hold the instanceData you passed in.

    var series = instanceData.series[0]

    To get the first row of data, use index value 0 within instanceData (it is a zero-based array). Following rows will of course use sequential index numbers (for example in a loop as shown in the following screenshots).

    var record = series[0];

    Then to access your data you can use "<variable_name>.<fieldname>".

    record.value;

    Overall the program looks like this:

    return function (instanceData) {    
    
                    var series0 = instanceData.series[0]
    
                    for (var index = 0; index < series0.length; ++index) {
                        
                        var record = series[index];
                        
                        var holder = new string;
                        
                        if ( "value1" == record.subcategory )
                        {
                            holder = record.value;
                        }
    
                    //Insert your code here
    
                    }
    }

    Then customise the code as required based on your needs.

    Sample CVC files

    Below is some examples of CVC files that you can use to test parameter usage. 

    https://community.jaspersoft.com/sites/default/files/wiki_attachments/cvc_samples_20150127.tgz

     

     


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