Skip to main content
15-Moonstone
Feb 26, 2022 5:56 PM UTC
Solved

About newEntry object and addRow to the result object to infotable when and where we need to add thi

Hello ,

 

I am trying to pull data from json based on various inputs. i have placed some conditions and write 3 if statements and in that if statements i have created var newEntry- new Object() and also write result.addRow(newEntry) in all 3 if statements. in logger its working fine but unable to display infotable and its still executing and goes into infinite loop.

so I want to know when and where need to create newEntry object and where i need to write result.addRow(newEntry). please help me out on this.

eg:

else if(leng==0){
var newEntry1=new Object();
newEntry1.Name="";
newEntry1.Number="";
newEntry1.partId="";
result.AddRow(newEntry1);

}


else if(leng==1){
var newEntry2=new Object();
newEntry2.Name=dt.values[j].Name;
newEntry2.Number=dt.values[j].Number;
newEntry2.partId=text;

result.AddRow(newEntry2);
}

 

 

 

 

Thanks

ksm

1-Visitor
Mar 1, 2022 1:53 PM UTC

Can you try creating the object out of these blocks, even if you have these blocks in a loop, then try to put the new object out of the loop. Ideally, if you create the object only once and add the rows to the object as per the condition it should work. It works something like this:

var obj = new Object();
for(var i=0;i<2;i++)
{
obj.A="Hello";
obj.B="There";
result1.AddRow(obj);
obj.A="T";
obj.B="R";
result1.AddRow(obj);
}
Where A and B are my fields of DataShape.
Thanks,

Mukul

4 replies

1-Visitor
Mar 1, 2022 1:53 PM UTC

Can you try creating the object out of these blocks, even if you have these blocks in a loop, then try to put the new object out of the loop. Ideally, if you create the object only once and add the rows to the object as per the condition it should work. It works something like this:

var obj = new Object();
for(var i=0;i<2;i++)
{
obj.A="Hello";
obj.B="There";
result1.AddRow(obj);
obj.A="T";
obj.B="R";
result1.AddRow(obj);
}
Where A and B are my fields of DataShape.
Thanks,

Mukul

Translate
KSM15-MoonstoneAuthor
15-Moonstone
Mar 2, 2022 4:20 AM UTC

Hi Mukul,

Thanks for your reply.

what ever you have suggested in the above code, there is a chance of overwriting the data which is already in result object. I means when 

var obj = new Object();
for(var i=0;i<2;i++)
{
obj.A="Hello";
obj.B="There";
result1.AddRow(obj);
obj.A="T";
obj.B="R";
result1.AddRow(obj);
}

The Highlighted result1 will be replace the data with new one.

 

Thanks

Mahaboob basha

 

Translate
1-Visitor
Mar 2, 2022 6:22 AM UTC

Nothing will be replaced, you have already added the previous row and then you are adding a new row. Here is the output of this code : If you see the output it is adding 4 rows(which is expected).

 

Mukul_0-1646202112194.png

 

Translate