cancel
Showing results for 
Search instead for 
Did you mean: 

How to hide a Sub Form when there are no rows in table.

Former Member
0 Kudos

Hello Experts,

I am trying to build a Adobe Form , which displays data using multiple tables . And each table has its own Sub form .  I am trying to hide the whole sub form when the table has no records .

Can this only be done by writing a script on the Adobe Form or is there any other way to achieve this ?

I have tried writing different variations of java script to check if the table is empty and change the 'presence' of sub form to 'hidden' . But it does not seem to work .

I would appreciate your help or any code snippet on which can achieve this .

Thanks,

Rohit

Accepted Solutions (1)

Accepted Solutions (1)

rakesh_m2
Contributor

Hi Rohit,

In subform properties, during repeating the subform, remove 'Min = 1', if no rows are there in the table, it wont print the subform.

Thanks,

Rakesh

Answers (5)

Answers (5)

Former Member
0 Kudos

I am new to adobe form.

But I solved the similar issue using flag which i passed from driver program to form.

In driver program when table has no data I set flag which I pass to form and correspondingly hide  subform using JavaScript. I think this least help you.

Former Member
0 Kudos

Hi Rohit,

I know it's been a while since you opened this thread but I want to help those who come across this topic.

To hide a parent subform if there are no values in a table (rows.count == 0) will work like that:

Let's assume you have a subform called ITEMS on your form. That subform contains, among other elements, a table called ITEMS_CONDITIONS with binding to a table in your interface.

What you have to do now is the following: In the initialize event of the subform ITEMS you enter the following code:


//ITEMS_CONDITIONS is the name of the Table, DATA is the name of the row element

var vRows = ITEMS_CONDITIONS.DATA.all.length;

//then you check how many rows (entries) that table has

//if you have less than 1 entry, you hide the parent element, which is the subform

if (vRows < 1) {

this.parent.presence = "hidden";

}

Hope this will help,

Best Regards,

Patrick

Former Member
0 Kudos

Hi Patrick,

I have done the changes as mentioned by you. If the number of entries in the table is greater than or equal to 1, then variable vRows will hold those many entries, but if there are no entries, vRows is not holding any value. Also I have put condition (as mentioned below) to check if it is null but it is also not working.

if (vRows == null)then

*my subform should be hidden;

endif

Can you please let me know your views on this.

Regards

Mini

prajeshdesai
Contributor
0 Kudos

Use below script on data::initialize event.

Hope this helps.

Former Member
0 Kudos

Hi Prajesh,

I have used the resolve nodes using Form Calc. Below is the code:

var count = $.resolveNodes("datasubform[*]").length;

It is working fine when count is >= 1 but it does not hold 0 when there are no records.

Regards

Mini Duggal

prajeshdesai
Contributor
0 Kudos

i have tested in Form Calc and JavaScript it's 0 and also works well for me.

Check it, and let us know it's resolved or not.

Former Member
0 Kudos

Hi,

The Pop-up (message box) is not coming for me(tried it in FormCalc and Javascript both). Regarding the issue of 0 not coming if table is blank, it still exists.

prajeshdesai
Contributor
0 Kudos

you need to run your pdf DYNAMICALLY to see pop-up.

in Print Preview -> Edit Menu -> Form Properties -> General Tab -> Select Dynamic Form

in Report Program -> /1BCDWB/DOCPARAM-DYNAMIC = 'X' in form calling fm.

Former Member
0 Kudos

In my case, the driver program are SAP Standard programs, so to set the Dynamic flag as 'X'(even in debugger)  will be time consuming process.

The role of the Pop-up used by you is to check the value of the variable IMTEST. I have already done the same thing by holding the count of records of the table in a text field (Date) i.e. temporarily created in the form. Below code indicates the same:

var count = $.resolveNodes("Comprehensive[*]").length;

$.parent.parent.parent.Date = count;

Text Field is showing the count if it is >=1 but not for 0.

prajeshdesai
Contributor
0 Kudos

Check below,

IMTEST.IsNull

also check your if condition syntax

also refer IS THAT FIELD EMPTY

Hope this helps

Former Member
0 Kudos

Hi Prajesh,

I have debugged the standard program also and set the dynamic flag as well. I have done the Scripting using Javascript (to hide the subform if a table present in this subform has no no records) and this script is working.

The only issue that I am facing now is when I am displaying the number of records of the table in the pop-up, it is not getting displayed . Please find below the code for your reference:


xfa.host.messageBox(COUNT);

But when display the pop up with just a message e.g Welcome, it gets dispalyed.Can you please let me know what could be the issue.

Regards

Mini

prajeshdesai
Contributor
0 Kudos

Try below, COUNT is integer type variable, and method messageBox required a string type parameter so you need to convert into string.

xfa.host.messageBox(COUNT.toString());


or


xfa.host.messageBox("Count :" + COUNT);


Hope this helps.


Also open a new thread for this issue, so it's helps to others also.

Former Member
0 Kudos

Hi Prajesh,

Can you please let me know your views on the below query:

I have a subform1 which includes some 4-5 subforms (let us say child subforms). Each child subform has a Text and its value (Text field). We have written individual scripts to hide child subform if there is not value in the Text field. But we need to hide the outermost subform i.e subform1 if all its child subforms do not hold any value. We can do this by checking respective text fields of child subform but in this case we have to write number of script lines.

Is there any other way that we can do this.

Regards

Mini

prajeshdesai
Contributor
0 Kudos

Kindly ask in new thread.

Former Member
0 Kudos

Hi Prajesh,

I posted this query in a new thread only but it got rejected that is why I have to ask it here.

Regards

Mini

Former Member
0 Kudos

Hi Rohit,

It's late, but maybe, my response will serve.

It's  for second  point issue : The adobe form is skipping the first row of the internal table and displaying the rest of the rows..

It may comes of the binding tab of  your  table.

You have to check it again,  perhaps in the subform of the table, your binding  is  made with a record  of the table and not with the table itself.

So ADOBE reads your first record, and when binding of the bodyrow subform it reads the next one.

christian.

Former Member
0 Kudos

Hi Rakesh,

Removing the "Min = 1 " is working when rows are not in the table . But now i am encountering a weird problem when the table has rows in it.

The adobe form is skipping the first row of the internal table and displaying the rest of the rows.

Currently I have the binding of the sub-form set as

$record.itab2.DATA[*]

and Repeat subform for each data item is checked with Min and Max unchecked.

Any advise or help is appreciated.

Thanks,

Rohit

rakesh_m2
Contributor
0 Kudos

Rohit,

There might be any other instance on form binded to same table field before calling sub-form, where it is taking first row values.  Can you please check once

--

Rakesh

Former Member
0 Kudos

Hi Rakesh,

There is no other instance on the Form that is referencing the particular internal table.

The table is being referenced once in the binding of the Sub-Form and then in the data section of the table itself . That's it no other reference else where.

Regards,

Rohit

Former Member
0 Kudos

Hi Rohit,

Can you try this? Assign the Min = 1 back, and wrap your table into a subform, say subform A.

Under initialize event of subform  A, put this coding. formcalc script, run at client side

if ( $record.itab2.DATA[*] == null ) then

this.presence = "hidden"

else

this.presence = "visible"

endif

regards,

Xiang Li

Former Member
0 Kudos

Hi Rohit

I used formCalc and it works fine

the code I used (in the form:ready event of the subform):

if ( $.table.row.count == 0 ) then

     $.presence = "hidden"

endif

About the first row missing:

it looks like you are not using a wrapper for your rows,

the meaning is that you need to build the PDFSource node with the following hirarchy

table node with cardinality 1 to 1 -> wrapper node with cardinality 0 to n -> data node with cardinality 0 to 1 with an attribute for each colomn.

then set the binding of the table to the table node,

the binding of the row to the wrapper node (don't forget to sign the repeat row for each data item checkbox),

and the binding for each cell to the attributes of the data node.

withoute using the wrapper the first row of the table is 'taken' for the row binding.

the subform needs no binding.

hope I helped

Shai

navip
Active Participant
0 Kudos

Hi Rohit,

If you have placed the subform in Design page:Try to use the below FormCalc in event: formready

                                                                                                                                                

Assuming  that you have 5 rows in the table and want to validate each row……

If ($.parent.row1 == null ) and

    ($.parent.row2 == null  and

    ($.parent.row3 == null  and

    ($.parent.row4 == null  and

    ($.parent.row5 == null )  then

$.presence = “hidden”

Else

$.presence = “visible”

 

If you have placed the subform in Master page:Try to use the above FormCalc in event: layoutready

Hope it works!

Naveen

Former Member
0 Kudos

Hi Rohit,

These are the formcalc scripting ..

this.presence = "visible"

this.presence = "hidden"

Using javascript, you need to be very careful on the way you write the code. example make sure there is semicolons as statement terminators, etc.

Do you mind to paste your code here on the condition how you check if there is data in the table , how you make the subform visible/hidden, and which event you put your code in.

Thanks.

regards,

Xiang Li