Visokio website     Downloads     Video tutorials     KnowledgeBase  
JavaScript: script using nested loops? - Visokio Forums
JavaScript: script using nested loops?
  •     enrico68 September 25, 2012 9:48AM
    I'm writing a script with an outer loop on ABICapoGruppo and, for each ABICapoGruppo element, an inner loop on a variable number of elements.

    For each outer loop element (ABICapoGruppo) the resulting table has to show:
    - an header row
    - a serie of detail rows
    - a summary row.

    The number of detail rows is different for each ABICapoGruppo element.

    At the moment I've written the following script (I've cut out all the details of data calculations).

    Only the outer loop works fine, printing the description of ABICapoGruppo but no details from inner loop are produced.

    I think that the key point is the inner array variable declaration that, for each outer loop cicle, is based on the current value of the outer loop element.

    <#/*TABLE HEADER ROW*/#> [......] <#<br />//START OF OUTER LOOPvar array = subset_uniquesList('ABICapoGruppo', SUBSET('ABICapoGruppo',null,'<>'));for (var i in array) { var val = array[i]; #> <#/*ABICapoGruppo HEADER ROW*/#> [......] <#<br /> //START OF INNER LOOP array2 = subset_uniquesList('ABIAppartenente',SUBSET('ABICapoGruppo', '" + val+"') ); for (var j in array2) { var val2 = array2[j]; #> <#/*REPEATED DATA ROW*/#> [......] <# } #> <#/*ABICapoGruppo SUMMARY ROW*/#> [......] <# } #>

    Is this the right way to write this script?

    Attached to this post a doc word with a more readable version of this script. - Thanks
    Attachments
    script.doc 22K
  • 3 Comments
  •     enrico68 September 26, 2012 6:01AM
    I'm trying to find the 'focal point' of the problem. It seems that using the below statements it's not possible to set the value of array2 depending on the value of val variable.

    var array = subset_uniquesList('ABICapoGruppo', SUBSET('ABICapoGruppo',null,'<>'));
    //START OF OUTER LOOP
    for (var i in array) {
    var val = array[i];
    var array2 = subset_uniquesList('ABIAppartenente',SUBSET('ABICapoGruppo', '"+ val+"') );
    Writing the variables <#=array#>;<#=val#>;<#=array2#> I get the following:

    sun.org.mozilla.javascript.internal.NativeArray@f581f8;05034;(no value);
  •     michael September 26, 2012 9:38AM
    The second subset is filtered by the string constant [" + val+"], wrong string quotes (you don't need them):

    SUBSET('ABICapoGruppo', '" + val+"')

    this should be

    SUBSET('ABICapoGruppo', val)

    An example file is in the attachment.
  •     steve September 27, 2012 6:56AM
    Enrico,

    Since you're using scripting, you will benefit from trying out the alpha build of 2.8. This has better support for scripting, such as syntax highlighting in the Content View, and better script error handling.

    In order to give you access, I've upgraded your forums account to Alpha Partner. Please now see here: http://forums.visokio.com/discussion/1671/omniscope-2.8-alpha-now-available-for-private-testing

    Steve

Welcome!

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

Sign In Apply for Membership

Tagged