cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

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

KSM
15-Moonstone
15-Moonstone

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

ACCEPTED SOLUTION

Accepted Solutions
Mukul
14-Alexandrite
(To:KSM)

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

View solution in original post

4 REPLIES 4
Mukul
14-Alexandrite
(To:KSM)

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

KSM
15-Moonstone
15-Moonstone
(To:Mukul)

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

 

Mukul
14-Alexandrite
(To:KSM)

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

 

KSM
15-Moonstone
15-Moonstone
(To:Mukul)

Thanks Mukul,

Its working fine now.

You can mark as a solution.

 

Announcements


Top Tags