How to read queryArray by index

Cuto Calleja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2016

Populating a dataTable array I am using this code working properly:

 

var result = PocketQuery.queryArray();

  var dataTable = [['FIELD1', 'FIELD2']];

    jQuery.each(result, function(index, row) {

          dataTable.push([row.FIELD1,row.FIELD2]);

     }

 

In order to reuse the same template for other queries, I intend to replace the line in bold by

dataTable.push([row[0], row.FIELD2]); ... but despite that there is no error, I obtain no value for FIELD1...

 

Any idea how to make "row[0]" working properly will be highly appreciated!!! wink

 

Thanks in advance

 

 

1 answer

1 accepted

0 votes
Answer accepted
Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2016

Hi Cuto,

Please try like this:

var columns = PocketQuery.queryColumns('yourQueryName');
var result = PocketQuery.queryArray('yourQueryName');
var firstColumnName = columns[0];
jQuery.each(result, function(index, row) {
	dataTable.push([row[firstColumnName],row.FIELD2]);
});

Let me know if this helps!

Regards, Felix (Scandio)

Cuto Calleja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2016

Excellent! Thanks again Felix!!!!!

I let 'yourQueryName' empty and it works... what allows me to use my template in many queries!

Regards

Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2016

Yes. It will work as long as you only have one PocketQuery macro on your page smile

Cuto Calleja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2016

Ah!

I have many PocketQuery macros in the page... and it works!

Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2016

In that case, queryArray() will return the result of the last macro that was run on the page. Note that queryColumns(...) requires a query name. You can also retrieve the query name of the current PocketQuery macro in the template.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events