cancel
Showing results for 
Search instead for 
Did you mean: 

Delete a Row based on a blank field in the Row

Former Member
0 Kudos

Hi all,

I have a table with Multiple rows.

Table : XYZ

Row 1 : field1 X field2 Y field3 Z

Row 2 : field1 A field2 <blank> field3 C

Row 3 : field1 1 field2 2 field3 3

I am using Tables in the Adobe Form .

Based on the Above table data in Row 2 has a blank value in field 2.

So , I would like to delete that Row before displaying it on the Form using Script Editor.

I have Tried using this.rawValue = "hidden". but didnt work.

can anyone suggest a solution Please.

Thanks.

Tk

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can solve this problem with javascript code. Try the following script in the appropriate event.

var tab1 = xfa.resolveNodes("MainForm.SubForm1.Table[*].Row[*]");
var tab_len = tab1.length;
for (var i=0; i<tab_len; i++)
{
   var val = tab1.item(i).Field2.rawValue;
   if (val == "" || val == null){
	tab1.item(i).instanceManager.removeInstance(1);
   }
}

This will solve your issue.

Former Member
0 Kudos

Hi,

Sanoosh code is correct but a small correction in it. it should remove the i occurance of the instance, not the 1 every time.

tab1.item(i).instanceManager.removeInstance(i);

Cheers,

Sai

Former Member
0 Kudos

Hi Sai,

I just typed script in the thread and didn't tested it.

Anyway, Thank you for pointing it out. But now I feel there is one more mistake with that script. It will work fine if only one row has a blank field. If there are more than one row with blank fields, then it will give you a javascript error (index out of bound).

I think when we remove the row instance in a for loop, the index gets changed. So when you loop the table it has to be in the reverse direction. Here is the revised script.

var tab1 = xfa.resolveNodes("MainForm.SubForm1.Table[*].Row[*]"); 
var tab_len = tab1.length; 
for (var i=tab_len-1; i>0; i--) 
{ 
   var val = tab1.item(i).Field2.rawValue; 
   if (val == "" || val == null){ 
         tab1.item(i).instanceManager.removeInstance(i); 
   } 
}

Thanks & Regards,

Sanoosh

Edited by: Sanoosh P K on Feb 16, 2011 11:02 AM

Former Member
0 Kudos

Sorry Mate.

One more typo, dont think i am so picky..

The loop should be from length-1 to >=0.

Your code runs from last row to 1st row, it will leave 0th row.

Cheers,

Sai

Former Member
0 Kudos

Ha ha... Great Sai.

You are always welcome for any kind of suggestions or corrections.

By the way... TK,

Did your problem got solved?

Thanks & Regards,

Sanoosh

Answers (0)