Using custom style / extension JS to read visual results

When using custom styles to write JS you usually need a way to read the results of the query.

Arcadia provides JS API to read query results and you can find the more information here:
http://documentation.arcadiadata.com/4.5.0.0/#pages/topics/arcapi-cust-exten-js-apis.html#arcapi-cust-exten-js-apis-dataresult-functions

In the below example we have created a simple KPI tabular visual, and using the arcapi.dataResult() function we will obtain the query results and send out the value as a parameter.

The results is as follows:

image

The Javascript code style :

 return {
    version: "1",
    afterDraw: function() {

   // ARCAPI to get query results
   var d = arcapi.dataResult();
   var rows = d.rows();
   var cols = rows[0].length;
    
   // Browser dev console logs
   console.log(rows[0]);
    
   // ARCAPI to send parameters
   arcapi.sendParameters({"maxdate": rows[0][0]});
            
 }
};

For a catalog of Arcadia specific JS API functions refer to : http://documentation.arcadiadata.com/4.5.0.0/#pages/topics/arcapi-cust-exten-js-apis.html#arcapi-cust-exten-js-apis-arcapi-functions

1 Like

Hi Shaun,

I’m trying out some stuff from above. Unfortunately it throws an error. Do I need version 4.5 for this?

Thanks!

  1. I’ve created a simple table with one cell maxdate.
  2. Assigned the following JS script to it:

// Purpose: Set the logged in user’s username as a parameter within a visual or application
return function() {
_ var f = function() {}; _
_ f.version = “1”;_
_ _
_ f.init = function () {_
_ // ARCAPI to get query results_
_ var d = arcapi.dataResult();_
_ var rows = d.rows();_
_ var cols = rows[0].length;_
_ };_

_ f.init();_
_ return f;_
}();

  1. It throws the following error:
    Visual 7006 - Error registering custom js: TypeError: Cannot read property ‘rows’ of undefined

@waiman

The results are only available in the “afterDraw” as my example shows. Can you instead copy & use my example?

Or else you have to modify you example to include the afterdraw function:

f.afterDraw = function() {
    // get results & set parameters
   ....
   ....
        }
    }

Hey Shaun,

Thanks it works. There was an error that came from the characters here: version: “1” - I just replaced them with normal quotation marks.

Thanks for your help.

Cheers,
Wai-Man

1 Like

@waiman thanks for the note, I tried to fix the example to have more proper quotation marks.

1 Like