Visokio website     Downloads     Video tutorials     KnowledgeBase  
Content View: Scripting question - Visokio Forums
Content View: Scripting question
  •     enrico68 September 24, 2012 8:04AM
    Hi,

    I'm trying to create a content with a table included using the following script:

    //START OF LOOP
    var array = subset_uniquesList("ABIAppartenente");
    for (var i in array) {
    var val = array[i];
    #>

    <#/*REPEATED ROW*/#>



    <#=val#>
    <#/* example of inserting a script expression */#>


    <#= formula("SUBSET_SUM('Netto', SUBSET('ABIAppartenente', '" + val+"'))") #>
    <#/* example of embedded formulas using the formula() function from within a script*/#>


    <#= formula("RECORDCOUNT(SUBSET('ABIAppartenente', '" + val+"'))") #>
    <#/* example of embedded formulas using the formula() function from within a script*/#>


    {{RECORDCOUNT(SUBSET2('Dataregolamento','ABIAppartenente', '04/09/2012','" + val+"'))}}
    <#/* example of embedded formulas using the formula() function from within a script*/#>


    <#<br />}
    The table is created on a loop on ABIAppartenente code and have different columns:

    - first column is the ABIAppartenente code itself;
    - second column is a total amount for each ABIAppartenente code;
    - third column is the count that contributes for each code;
    - fourth column counts record for each ABIAppartenente code for a fixed date.

    Everything works fine except for last column that return always 0 (for each ABIAppartenente, also if there are records for each ABIAppartenente code and the indicated date Dataregolamento).

    So I'd like to know if anyone have an idea about the problem in using the SUBSET2 as indicated - Thanks
  • 3 Comments
  •     michael September 24, 2012 9:38AM
    Hi Enrico - The syntax for the last column is not correct. See below and attached IOK file. It started working after wrapping with formula("....") .


    <#<br />//START OF LOOP
    var array = subset_uniquesList("ABIAppartenente");
    for (var i in array) {
    var val = array[i];
    #>

    <#/*REPEATED ROW*/#>


    ABIAppartenente = <#=val#> ,
    <#/* example of inserting a script expression */#>


    netto=<#= formula("SUBSET_SUM('Netto', SUBSET('ABIAppartenente', " + val+"))") #> ,
    <#/* example of embedded formulas using the formula() function from within a script*/#>


    count=<#= formula("RECORDCOUNT(SUBSET('ABIAppartenente', " + val+"))") #> ,
    <#/* example of embedded formulas using the formula() function from within a script*/#>

    date=<#= formula("RECORDCOUNT(SUBSET2('Dataregolamento','ABIAppartenente', '04/09/2012', '" + val+"'))") #> ,
    <#/* example of embedded formulas using the formula() function from within a script*/#>

    <br />

    <#}#>


  •     enrico68 September 24, 2012 11:06AM
    It works!

    But how to use ">=" operator with dates (or strings)?? The following formula return "true" (not a number of records):

    date=<#= formula("RECORDCOUNT(SUBSET2('Dataregolamento','ABIAppartenente', '04/09/2012', '" + val+"', '">="', '='))") #>
  •     michael September 24, 2012 11:31AM
    1) To use >= convert text to the date type with TEXTTODATE function;
    1) val - is a number, we shouldn't cast to a string by using quotes around val.

    This should work:

    date=<#= formula("RECORDCOUNT(SUBSET2('Dataregolamento','ABIAppartenente', TEXTTODATE('04/09/2012'), " + val+", '>=', '='))") #> ,

Welcome!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership