Skip to main content
12-Amethyst
November 29, 2023
Solved

Filter in an for

  • November 29, 2023
  • 1 reply
  • 1187 views

Hello there,
I have this code: 
for (var x = 0; x <me.kpis.length; x++) {
var line=me.kpis[x].Line;
var json_yt = Things["Name of Things"].GetKpis({
Lines: line,
_timeOption:"Yesterday"
});


var json_yt = Things["Name of Things"].GetKpis({

Lines: line,
_timeOption:"All month"
});

if(line.includes("line1")) {

var kpis_value_yt_value =json_yt.array.filter(x=>x.kpis)[0]["kpis"];

 

I want to get Kpis from json_yt but when I try to get data from there I have a message: 

 Error executing service Test. Message :: TypeError: Cannot read property "kpis" from undefined - See Script Error Log for more details.
 
When I read this service : 
var result = (json_yt);
I have an array with all data. 
When I try to do this with _timeOption "All month" it works, only with Yesterday it wont works. 
I dont know if I made a mistake or the platform have some problems. 
Can someone help me?
Thanks
 
 
Best answer by tenegabi

I found a way to filter. 

if (json_yt.array[0] == undefined ) {
continue;}

I make an if and for me it was a problem because always I put null, but must check what the value return your array. 

Thank anyway.

1 reply

tenegabi12-AmethystAuthorAnswer
12-Amethyst
December 4, 2023

I found a way to filter. 

if (json_yt.array[0] == undefined ) {
continue;}

I make an if and for me it was a problem because always I put null, but must check what the value return your array. 

Thank anyway.