Skip to Content

Increment of Numeric Values using Javascript in SAP Adobe forms.

We might come across certain situations where we need to increment the numeric counter

  1. Dynamically.

For example:

We have a table of contents in order

1 – A

2 – B

3 – C

4 – D

5 – E

Here the counter is starting from 1 to 5 depending on the respective alphabets (In real world dynamic Values).

If we have a requirement to display only:

A

C

E

Then the corresponding counter should be as :

1 – A

2 – C

3 – E

But not as

1 – A

3 – C

5 – E.

In order to deal with these kinds of situations, we can write form calc or java script at the script editor.

Example code:

 

In the below screen shot you have the increment text field in the Hierarchy node and the out on the design view.

In the Script editor we have assigned value this.rawValue = 0.

And there is not dynamic binding for the text field Increment.

Initialize.JPG

In order to obtain the increment counter dynamically for the first column of the table. We need to proceed in the following way:

Create a text field and assign its value to 0.

Syntax:

Event — Initialize event.

Language — Java Script.

Run At — Client.

Script :

this.rawValue = 0;

The above code initializes the value of the Increment field to “Zero”.

After initializing the value to zero, now we have to increment the counter dynamically depending on the display of the column two.

To obtain the above scenario, we need to writ the following Java script.

var a;

a = this.parent.parent.parent.parent.parent.INCREMENT.rawValue;

b = ++a;

  1. this.rawValue = b ;
  2. this.parent.parent.parent.parent.parent.INCREMENT.rawValue = b;

Explanation:

  1. Declaring a local variable “a’.
  2. Calling the Increment value and assigning that value to the local variable ‘a’.

    Depending on the depth of the field where we are writing the JavaScript for counter,

    We need to refer those many ‘parents’.

  1. In our case the Javascript is written at 5th level from parent i.e. Increment.
  2. As increment is assigned to zero.
  3. At first instance the value of a = 0.
  4. The value of  ‘b’ becomes 1.
  5. And later this ‘b’ value is assigned to the column 1 value. And this B value is assigned back to the Increment for using down the form.
  6. As the rows of the table increase the counter value increases as the local variable always refer to the INCREMENT value and this increment value is always being modified with updated incremented value.
  7. Hence the values of the column 2 ,3,4,5 etc display according to the incremented values.

Incase if we want to hide any of the rows in middle we can write Formcalc or Javascript to hide the rows.

Regards,

Varun

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Shai Lapidot

    1. What event do you use for the second script?

    2. Why doen’t you use  this script(in form:ready event):

    this.rawValue = this.parent.index + 1;

    parent in this case is the table row, and +1 because the row indexes start from 0.

    (0) 
    1. Varun Vadnala Post author

      1.Initialise event.

      2.The answer which you have provided will work in a table.The solution which i have provided works for both incrementing the counter in the table as well as incrementing the numericals for the side heading of the paragraphs.

      (0) 

Leave a Reply