Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Yoshidaqlik
Creator II
Creator II

Return more than 60,000 lines in extension

Hi All

please can someone help me with the data return

I can't get data from all rows for extension

I'm using the code below

for (var d = 0; d <= 600; d++) {
				var requestPage = [{
					qTop : d * 100,
					qLeft : 0,
					qWidth : 10, 
					qHeight : 100
				}];
				 self.backendApi.getData(requestPage).then(function(dataPages) {
					for (var e = 0; e <= dataPages[0].qMatrix.length; d++) {
						dados.push(dataPages[0].qMatrix[e][0].qText);
					}
				});
			}
			
			console.log(dados);

 

I don't understand why the data doesn't appear when I use the console.log

 

Thanks a lot for the help

YoshidaQlik https://www.youtube.com/channel/UC1I9P8MqCZEhB6Nw3FdSqng
Labels (1)
1 Solution

Accepted Solutions
Yoshidaqlik
Creator II
Creator II
Author

I ended up using the code below

became functional

async function obterDados(){
				for (var d = 0; d < 3; d++) {
					var requestPage = [{
						qTop : 100 * d,
						qLeft : 0,
						qWidth : 1, 
						qHeight : 1000
					}];

					const dadosObtidos = await self.backendApi.getData(requestPage).then(function(dataPages) {
						return dataPages[0].qMatrix;
					})
					
					
					for (var e = 0; e < dadosObtidos.length; e++) {
						//console.log(dadosObtidos);
						var texto = "<tr><td>" + dadosObtidos[e][0].qText + "</td></tr>";
						document.querySelector('#tabelanova').insertAdjacentHTML('beforeend',texto);
					}
				}
			}
			
			obterDados();

 

Thanks to all for your help.

YoshidaQlik https://www.youtube.com/channel/UC1I9P8MqCZEhB6Nw3FdSqng

View solution in original post

4 Replies
oz_moyal
Creator
Creator

It seem because the getData is asynchrouns fucntion

so the for loop is finishing to run, before all the requests (promises) are finished (resolved)
so when u  console.log the the data is not yet inside "dados"


try to console.log  in the end of the
then(function{
....
console.log(dados);
}
to check it.
you will get few logs, but the last one should be full.

Yoshidaqlik
Creator II
Creator II
Author

doing so it returns the first and last loop.

the rest gave as a result undefined

 

Is it possible to make synchronous or make some kind of execution queue?

YoshidaQlik https://www.youtube.com/channel/UC1I9P8MqCZEhB6Nw3FdSqng
oz_moyal
Creator
Creator

seem u have error in your second for loop:

for (var e = 0; e <= dataPages[0].qMatrix.length; d++) {
dados.push(dataPages[0].qMatrix[e][0].qText);
}
the loop is on var  e, and u do d++,   u should do e++

u can push all the promises into an array
and then use promise.all (google it if u r not familiar with it)
and when it resolves, it means all the promises resolved.

Yoshidaqlik
Creator II
Creator II
Author

I ended up using the code below

became functional

async function obterDados(){
				for (var d = 0; d < 3; d++) {
					var requestPage = [{
						qTop : 100 * d,
						qLeft : 0,
						qWidth : 1, 
						qHeight : 1000
					}];

					const dadosObtidos = await self.backendApi.getData(requestPage).then(function(dataPages) {
						return dataPages[0].qMatrix;
					})
					
					
					for (var e = 0; e < dadosObtidos.length; e++) {
						//console.log(dadosObtidos);
						var texto = "<tr><td>" + dadosObtidos[e][0].qText + "</td></tr>";
						document.querySelector('#tabelanova').insertAdjacentHTML('beforeend',texto);
					}
				}
			}
			
			obterDados();

 

Thanks to all for your help.

YoshidaQlik https://www.youtube.com/channel/UC1I9P8MqCZEhB6Nw3FdSqng