cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Rows dynamically upon clicking the button

Former Member
0 Kudos

Hi,

I have an adobe form which is generated through the WDA. It has Header & Item Sections. In Item Section, i have an ADD Row button. Upon clicking the Add Row button, a new row should get appended into that item table section.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

I have a solution to solve problem with dynamically added rows in interactive form placed in WD4A. Because of nature of WD4A this rows aren't created in WD4A context so you lose them. Solution is to parse pdf string(converted to XML) directly after Submit a manually save each manually created row in pdf to some your itab. Then bind this table to your context and you have it!

Code:

DATA ls_context TYPE wd_this->element_context.

DATA lv_pdfsource LIKE ls_context-pdfsource.

data retezec TYPE string.

  • get element via lead selection

lo_el_context = wd_context->get_element( ).

  • get single attribute

lo_el_context->get_attribute(

EXPORTING

name = `PDFSOURCE`

IMPORTING

value = lv_pdfsource ).

DATA: l_fp TYPE REF TO if_fp.

l_fp = cl_fp=>get_reference( ).

DATA: l_pdfobj TYPE REF TO if_fp_pdf_object.

l_pdfobj = l_fp->create_pdf_object( ).

l_pdfobj->set_document( pdfdata = lv_pdfsource ).

l_pdfobj->set_extractdata( ).

l_pdfobj->execute( ).

DATA: pdf_form_data TYPE xstring.

l_pdfobj->get_data( IMPORTING formdata = pdf_form_data ).

DATA: converter TYPE REF TO cl_abap_conv_in_ce, formxml TYPE string.

Converter = cl_abap_conv_in_ce=>create( input = pdf_form_data ).

Converter->read( IMPORTING data = formxml ).

TYPE-POOLS: ixml.

DATA: l_ixml TYPE REF TO if_ixml.

l_ixml = cl_ixml=>create( ).

DATA: streamfactory TYPE REF TO if_ixml_stream_factory,

istream TYPE REF TO if_ixml_istream.

streamfactory = l_ixml->create_stream_factory( ).

istream = streamfactory->create_istream_string( formxml ).

DATA: document TYPE REF TO if_ixml_document.

Document = l_ixml->create_document( ).

DATA: parser TYPE REF TO if_ixml_parser.

parser = l_ixml->create_parser( stream_factory = streamfactory

istream = istream

document = document ).

Parser->parse( ).

Former Member
0 Kudos

Hi Manjunath,

You can use the below code and this is only in adobe form to add or delete rows in table dynamically.

Please follow the following thread:

[Dynamic Table Index Number|;

Also do remember that when you add the rows dynamically in Adobe Form and if you Submit(WebDynpro Submit Button) then the newly added rows will not be binded to the context of WebDynpro. There is a work around that in the WebDynpro Initialialisation Method i.e. "WDDOINIT" add the number of NULL rows to the respective table that are needed to be given to the End User for filling up the form. And when you activate and execute the form you will see all the rows that were added to that table in the Form.

Regards

Pradeep Goli

nikhilkup
Active Participant
0 Kudos

You can use the below code and this is only in adobe form to add or delete rows in table dynamically.

Create a table with the binding "Repeat Table for each data item" with min count as 1. similarly write this binding for the row with min count as 1. Also create only one row. And for header row make min count as 1 and max count as 1, in pagination make check the "Include header row in initial page" and also "include header row in subsequent pages". Now include create one button in "Header Row" make this as "Add" and one button in "Row" make this as "delete".

Now in the JavaScript editor for ADD Button: Click event

 // nTableLength stores the number of XML elements contained in TableName. 
var nTableLength = TableName.nodes.length; // nNumRow is used to calculate the number of rows contained in TableName. 
var nNumRow = 0;
// This script uses a For loop to cycle through all of the XML elements // contained in TableName. 
for (var nCount = 0; nCount < nTableLength; nCount ++) { // If the current XML element in Table2 is of type subform and it // is not a header row, then increment the variable nNumRow by one. 
// If the table included a footer row, this script would have to // account for it. 
// // Note: In the Adobe XML Form Object Model, all table rows are // considered subform objects. 
if ((TableName.nodes.item(nCount).className == "subform") & 
   (TableName.nodes.item(nCount).name !== "HeaderRow"))
  { nNumRow = nNumRow + 1;
  }
 } 

// An if-else statement is used to prevent form fillers from adding // more than the maximum number of seven rows to a table. 
if (nNumRow == 7) {
xfa.host.messageBox("The maximum allowable number of rows is 7. You cannot add any more rows.", "Warning", 3); } else { // This script uses the addInstance() method to add a new instance // of the RowName object contained in TableName. subformname.TableName.RowName.instanceManager.addInstance(1);
}

DELETE button: Click Event


// nNumRow is used to calculate the number of rows contained in TableName. 
var nNumRow = 0;
// nTableLength stores the number of XML elements contained in TableName. 
var nTableLength = TableName.nodes.length; // This script uses a For loop to cycle through all of the XML elements // contained in TableName. 
for (var nCount = 0; nCount < nTableLength; nCount ++) { // If the current XML element in TableName is of type subform, and it // is not a header row, then increment the variable nNumRow by one. 
// If the table included a footer row, this script would have to // account for that. 
// // Note: In the Adobe XML Form Object Model, all table rows are  // considered subform objects.
 if ((TableName.nodes.item(nCount).className == "subform") & 
    (TableName.nodes.item(nCount).name !== "HeaderRow")) { nNumRow = nNumRow + 1; } } // The Adobe XML Form Object Model uses a zero-based indexing system // for referencing objects. In this script, the variable nNumRow represents // the exact number of rows contained in Table1. To convert this to a usable // index value, the script subtracts one. 
nNumRow = nNumRow - 1;
// An if-else statement is used to prevent form fillers from removing // the single remaining row from a table. 
if (nNumRow < 1)
{
xfa.host.messageBox("The minimum allowable number of rows is 1. You cannot remove any more rows.", "Warning", 3); } else { // This script uses the removeInstance() method to remove the last // instance of the Row1 object (represented by nNumRow) contained // in TableName. 
//subform.
TableName.Row1.instanceManager.removeInstance(nNumRow); _ RowName.removeInstance(this.parent.index);
}

NOTE:

1. TableName is Name of your Table

2. RowName is the Name of Row in the Table it is like for eg. Row1 3. subformname is the subform name where the table is present With the above code you can dynamically add or delete rows

Former Member
0 Kudos

Hi Manjunath,

It could not be possible to catch added rows in Adobe form into WDA.

Please check this ...

Thanks.