Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Can't Build Filter string in Javascript

  1. #1

    Default Can't Build Filter string in Javascript

    I am building several reports that depend upon user selections entered via Prompt/Secure Filter Action Items. It seems like a general requirement for many reports to have a way of describing the filter criteria somewhere in the report head or foot. The correct solution seems to be to put a Resource Field in the report definition file so that the field references a property named 'filter'. Then I generate a string named 'filter' in the xaction and pass it as an input parameter to the report. This message plumbing is working.

    However, I am having trouble building my filter string in JavaScript. I have included a file called ReportFilter.js that has the functions I am using to build the string. The idea is to use the list of user selected values from the prompt/secure filter item and the corresponding result set. I have a convention where the first column in an ID and the second column is descriptive name and the column heading of the second column is a description like "Rank". So, I want to generate a string like "Rank in [ Hot, Warm, Unranked ]".

    I am able to reference a result set named 'rankList', but it is always empty, even though it was obviously populated in the previous Prompt/Secure Filter Action Item? Does the result set go out of scope after it was used once? Or is there some other reason that this isn't working?

    I can't attach *.js files, so here is the content of the ReportFilter.js referenced in the xaction.

    function QueryToArray( resultSet ) {
    // first column is key
    // second column is value
    var lvp = [];
    var rowCount = resultSet.getRowCount();
    for( i = 0; i != rowCount; i++) {
    lvp[resultSet.getValueAt(i,0)] = resultSet.getValueAt(i,1).toString();
    return lvp ;

    function ColumnName( resultSet, index) {
    var rsmd = resultSet.getMetaData();
    var colHeaders = rsmd.getColumnHeaders();
    return colHeaders[0][index].toString();

    function FilterStringForSelection(
    resultSet /* the first column holds the ID
    , the second holds the description*/
    , id /* the chosen ID value */ )
    var lvp = QueryToArray(resultSet);
    var filter = ColumnName(resultSet,1) + " is " ;
    filter += lvp[ id ];
    return filter ;

    function FilterStringForSelections(
    resultSet /* the first column holds the ID
    , the second holds the description*/
    , selectedIds /* a list of chosen ID values */ )
    var filter = ColumnName(resultSet,1) + " in [" ;
    var lvp = QueryToArray(resultSet);
    for( i = 0; i !== selectedIds.length; i++ ) {
    if( i !== 0) { filter += ", "; }
    filter += lvp[ selectedIds[i] ];
    return filter + " ]";
    Attached Files Attached Files

  2. #2

    Smile work around

    I added a relational process action called 'Get Ranks Again' that repopulates the result set rankList. This works, so I wonder if the original result set is released after it is used once. What (or where) are the rules that govern how long result sets are kept? It would be great if I wouldn't have to hit the database twice for the same data.

  3. #3

    Default Same solution with modification

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.