Visokio website     Downloads     Video tutorials     KnowledgeBase  
Content View: Custom scripting (2.7+) - Visokio Forums
Content View: Custom scripting (2.7+)
  •     steve October 28, 2011 12:43PM
    This new feature allows scripting-savvy publishers to write JavaScript inside their Content View in "view source" mode to create dynamic, adaptive text. This is very similar to Java Server Pages (JSP).

    For example, this allows you to repeat a section of your document for different subsets of the data.

    Scroll down for an example IOK file.

    Requires 2.7 b96 or later. You must use "View Source" mode (the "<>" button in the Content View toolbar).

    Existing syntax for dynamic content - {{ }}

    The existing dynamic content syntax is as follows. You might not use this, but if you have inserted dynamic content using the "f" button in the Content View, this is what happens in "view source" mode:

    <p><b>Total:</b> {{ SUBSET_SUM("Coupon") }}</p>

    This example inserts the dynamic result of the sum of the "Coupon" field according to whatever data results after applying your filters.

    New syntax for scripting - <# #> and <#= #>

      if (x==5) {
        y = 3;
      } else {
        y = 2;
      out.println("Write some text into the document, programmatically");
      var array = subset_uniquesList("Category");
      for (var i in array) {
        <b>Some text and HTML with <#=array[i]#> (inserted values)</b>

    This example demonstrates some JavaScript then uses a loop over unique values (after applying filters) in a field to repeat a section containing both static content and inserted script expressions.

    See the attached file for a larger example including comments.

    Functions available in script blocks

    formula("IF(RAND<0.5, true, false)")
    Dynamically evaluates an arbitrary formula using normal Excel-like formula syntax (not script)

    recordCount() or recordCount(subset)

    subset("Field name", "Field value") or subset("Field name", "Field value", "Operator")

    subset_sum("Field name") or subset_sum("Field name", subset)
    Note that all SUBSET_? functions are supported in JavaScript. The SUBSET_UNIQUESLIST function is slightly different in that subset_uniquesList() returns a JavaScript array rather than a single String containing a comma-separated list.

    textvalue(value) or textvalue(value, pattern)

    More to come.

    Example IOK file

    Open the attached file in 2.7 b96 or later. This shows a table whose rows come and go as you filter. Try filtering by the Category field. Also try dragging the date sliders to see the numbers update and the rows disappear.

    Expand the toolbars (or choose Toolbars > View toolbars), then click the "<>" icon to view source. The source is well-commented and shows different ways of working with scripting.
    Scripting example.iok 47K
  •     steve October 28, 2011 1:30PM
    More scripting-ready functions

    More standard formula functions from the functions guide have been made available in scripts.

    The function syntax is identical to that described in the functions guide.

    However, the names are case-sensitive and are listed below. Omniscope does also recognise all-caps or all-lowercase aliases, but the names below are are the primary names, chosen for readability and accepted code convention.

    Please see the functions guide for a complete list. Only functions with "In scripts" showing are currently supported. If you need any other functions, please post a comment here.
  •     steve October 30, 2011 11:29AM
    All these functions are now also available from within the SCRIPT formula function. See here for an example:
  •     steve July 16, 2012 12:17PM
    Please note that scripting functionality is now documented here:
  •     bfromson1 July 20, 2012 4:06AM
    This is really exciting - it means we can now have almost any report generated in a content view by use of the script coding. I have generated a small pivot table using the scripting and can see many more opportunities to use this functionality.

    File is attached, data is all totally random numbers.

    BTW does the first code snippet at the top in blue have a single = rather than a double one for a comparison operator!
  •     steve July 20, 2012 4:38AM
    Bernard, yes, this is very powerful, and we'll be building on it further shortly; watch this space. Thanks for spotting the typo.
  •     bfromson1 July 20, 2012 4:49AM
    We've just generated this version with selectable fields in the table - now the whole team are getting excited!

    At this rate we may even be able to silence all the Excel pivot-table groupies!
  •     steve July 20, 2012 4:50AM
    Re "Two way content table" - cool example, by the way!
  •     bfromson1 July 20, 2012 6:16AM
    Thanks! Did you check the later version with variable choice?
  •     steve July 20, 2012 9:20AM


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

Sign In Apply for Membership