cancel
Showing results for 
Search instead for 
Did you mean: 

how to make auto generation number in table field

Former Member
0 Kudos

i want to genearate one field in a table as auto generation.

how to make numbers in that.

Accepted Solutions (1)

Accepted Solutions (1)

nikhil_bose
Active Contributor
0 Kudos

I think one solution is creating a method where we are assigning values.

Context

Table(Node)

--No(attribute: type integer)

create a method and place the below code inside. you can set table serial number whenever you want by calling the same.


int size = wdContext.nodeTable().size();
for(int i = 0; i<size; i++) {
  wdContext.nodeTable().getTableElementAt(i).setNo(i+1);
}

nikhil

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Create a calculated attribute of type int and bind this to the column

Ex:

public java.lang.Integer getID(IPrivateTestCompView.IContextElement element)

{

//@@begin getID

return element.index();

//@@end

}

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

Do you want these auto generated numbers to be in sequential order or random order?

In case of Sequential numbers, Write function which will increament global variable by 1 and return its value. This function will be called from addRow function.

In case of delete row, decreament value of these global variable.

Initialize global variable to 0 in begin others section.

Regards,

Apurva

PradeepBondla
Active Contributor
0 Kudos

Hi,

If you need your auto generated number in a sequence use Nikil's code. or if you need that auto generated number as a random number.....

check if Math.random(); will be useful to you or not.

it generates a random number everytime. take that value and display in table field.

for example to make 5 digit auto generated random number...

*int five_digit = new Double( Math.random() * 100000 ).intValue();*

regards,

Pradeep