create 2d arrays with Rollbase API and store in client-side variables - Forum - Rollbase - Progress Community

create 2d arrays with Rollbase API and store in client-side variables

 Forum

create 2d arrays with Rollbase API and store in client-side variables

This question is answered

I want to create 2d arrays with the Rollbase API and store them in client-side variables. How do I do this?

This is what I tried but it just returns undefined:

var clientArray;

function myCallback(values) {
 clientArray = values;
}

rbf_selectQuery("SELECT field1#value,COUNT(field1#value) FROM object1 GROUP BY field1#value", 1000, myCallback);

alert(clientArray);

Thank you,

Greg

Verified Answer
  • Apologies for coming back so late. This is what happens when you mark a lot of stuff as TODO. Hope this still helps you.

    <div id="div1"> 
    
    <script> 
    function renderChart(labels, values) {
    	// variables for chart 
    	var canvasWidth = 600; 
    	var canvasHeight = 400; 
    	var pieXCoordinate = 150; 
    	var pieYCoordinate = 200; 
    	var pieRadius = 100; 
    	// create canvas 
    	var rIndustry = Raphael(document.getElementById("div1"), canvasWidth, canvasHeight); 
    	// create pie chart 
    	var pieIndustry = rIndustry.piechart(pieXCoordinate, pieYCoordinate, pieRadius, values, { legend: labels, legendpos: "east" }); 
    }
    
    $(document).on('chartDataAvailable', function(e, labels, values) {
    	renderChart(labels, values);
    });
    
    rbf_selectQuery("select R281410#value, sum(Stock_Value) from stock1 group by R281410#value", 1000, function(values) { 
    	// parse your data into 2 1D arrays	
    	var industryLabels = ["Manufacturing","Financial Services","IT"]; 
    	// and one for values: 
    	var industryValues = [43,20,18]; 
    	
    	$(document).trigger('chartDataAvailable', [ industryLabels, industryValues ]); 
    });
    
    </script>
    


All Replies
  • "..and so on, then pass that array to a client-side variable which can be used to generate the chart. That's where this question comes up as to how to use the results of the async AJAX call outside of the callback function"

    The custom events can help you with precisely that. Along with the event you can pass arbitrary data that listeners can get when the event is fired.

    What charting library are you using? And share a sample chart generation code assuming the results are available. I'll see if I can get a working example for you using selectQuery.

  • But you're on the right track. Just add code (inside EVAL block) to extract values you need.

  • Hi!!

    I think you can use server-side API it trued because Client -side API is AJAX concept . it work to 1 round trip ,1 request and 1 response . so you can use server-side api by Eval blog for get value to variable and if use want to display array for monitor. you can use "JSON.stringify(data)" .

    I hope to help you.

    Regards

    BOY

  • Thank you very much, Santosh. I am using g.Raphael (http://g.raphaeljs.com/). Code for a simple chart following the example of a breakdown of opportunities by industry is as follows:

    <div id="div1">
    
    <script>
          
    // ...at this point in the code the client-side 2d array is already parsed into two 1d arrays, one for labels:
    
    var industryLabels = ["Manufacturing","Financial Services","IT"];
        
    // and one for values:
    
    var industryValues = [43,20,18];
    
    // variables for chart
      
    var canvasWidth = 600;
    var canvasHeight = 400;
    var pieXCoordinate = 150;
    var pieYCoordinate = 200;
    var pieRadius = 100;
    
    // create canvas
    
    var rIndustry = Raphael(document.getElementById("div1"), canvasWidth, canvasHeight);
    
    // create pie chart
    
    var pieIndustry = rIndustry.piechart(pieXCoordinate, pieYCoordinate, pieRadius, industryValues, { legend: industryLabels, legendpos: "east" });
    
    </script>


    If you can show me the code for the custom event to create the client-side Javascript 2d array that would be awesome -- thank you!

  • Thank you, BOY. When I try JSON.stringify it just turns the value of org.mozilla.javascript.NativeJavaArray@67a4e0d1 into a string "org.mozilla.javascript.NativeJavaArray@67a4e0d1", it does not create an array. Am I missing something?

  • Apologies for coming back so late. This is what happens when you mark a lot of stuff as TODO. Hope this still helps you.

    <div id="div1"> 
    
    <script> 
    function renderChart(labels, values) {
    	// variables for chart 
    	var canvasWidth = 600; 
    	var canvasHeight = 400; 
    	var pieXCoordinate = 150; 
    	var pieYCoordinate = 200; 
    	var pieRadius = 100; 
    	// create canvas 
    	var rIndustry = Raphael(document.getElementById("div1"), canvasWidth, canvasHeight); 
    	// create pie chart 
    	var pieIndustry = rIndustry.piechart(pieXCoordinate, pieYCoordinate, pieRadius, values, { legend: labels, legendpos: "east" }); 
    }
    
    $(document).on('chartDataAvailable', function(e, labels, values) {
    	renderChart(labels, values);
    });
    
    rbf_selectQuery("select R281410#value, sum(Stock_Value) from stock1 group by R281410#value", 1000, function(values) { 
    	// parse your data into 2 1D arrays	
    	var industryLabels = ["Manufacturing","Financial Services","IT"]; 
    	// and one for values: 
    	var industryValues = [43,20,18]; 
    	
    	$(document).trigger('chartDataAvailable', [ industryLabels, industryValues ]); 
    });
    
    </script>
    


  • Awesome, thank you so much, Santosh!!

    Greg