Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member186319
Participant

Merging internal table cells dynamically in SAP Adobe forms using Java script code

This blog describes how to merge cells dynamically in a table of SAP Adobe forms.

Prerequisites

  • Basic knowledge on Adobe designing and
  • Adobe Java Scripting.

Customer requirement is to have the table format as per the below screen shot.

Observations from the above requirement:

  1. We can simply say it is an M x 9 matrix with different widths for each column.
  2. The first four table columns (table cells) change dynamically.
  • Column-1: Outcome
  • Column-2: Output
  • Column-3: Activity
  • Column-4: Estimated completion date

Depending on which we have to merge the first four table columns (table cells) dynamically..?

Answer:

  1. If first cell (Outcome) contains data, then we need to merge the first 3 table cells and show the complete data related to Outcome only.
  2. If second cell (Output) contains data, then we need to merge the Output and Activity table cells and show the complete data related to the Output only.
  3. If third cell (Activity) contains data, then no action is required. Leave this cell as is.
  4. I just crop the last two rows from the above table provided in the customer requirement.

   In the above table, red border indicates that the first four cells are merged...why..?

   Answer:

   In this case Outcome, Output, Activity and Estimated Completion Date cells are empty.

   So, we need to merge all the four cells into a single cell.

Procedure on how to achieve this functionality:

In this requirement I am just giving you a brief overview of Java script coding part involved not the Adobe form table design.

1. After the completion of adobe table design, select the table cell (Outcome cell) as shown below and write the Java script code in the initialize event.

Here is the Java script coding part in the adobe initialize event related to Outcome.

2. Select the table cell (Output cell) as shown below and write the Java script coding in the initialize event.

Here is the Java script coding part in the adobe initialize event related to Output.


Step by step explanation of Java script coding part related to “Outcome”:

Step-1:

Calculate no of rows in a table using the following Java script coding:

My adobe table name: GT_PROJECT

My adobe table body: GT_PROJECT.DATA



Java script syntax to calculate no of rows in a table:

var numrows = xfa.resolveNodes("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA[*]").length;

Step-2:

Loop each row:

for (var i=0; i<numrows; i++)

First take the values from the four cells:

Cell-1 -> Outcome:

outcome = xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].OUTCOME").rawValue;

Cell-2 -> Output:

output = xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].OUTPUT").rawValue;

Cell-3 -> Activity:

activity = xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].ACTIVITY").rawValue;

Cell-4 -> Latest finish / estimated completion:

latfinish = xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].LATEST_FINISH").rawValue;

Step-3:

Use appropriate conditions as required:

if((outcome == null) && (output == null) && (activity == null) && (latfinish == null))

{

xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].OUTCOME").colSpan = "4"; 

  xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].OUTPUT").presence = "hidden";

xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].ACTIVITY").presence = "hidden";

xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].LATEST_FINISH").presence = "hidden";

}

else

{

if (outcome !== null)

{

xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].OUTCOME").colSpan = "3"; 

xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].OUTPUT").presence = "hidden";

xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].ACTIVITY").presence = "hidden";

}

else

{

xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].OUTCOME").colSpan = "1"; 

xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].OUTPUT").presence = "visible";

xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].ACTIVITY").presence = "visible";  

}

}

delete outcome;

}

Step by step explanation of Java script coding part related to “Output”:

Step-1:

Follow the first two steps as explained above.

Step-2:

Use appropriate conditions as per required:

if (output !== null)

{ xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].OUTPUT").colSpan = "2";   xfa.resolveNode("data.PAGE11.Newtable.#subform[0].GT_PROJECT.DATA["+i+"].ACTIVITY").presence = "hidden";   

}

else

{

 

}

delete output;

Resultant PDF Output:

8 Comments
Labels in this area