### Post

2 followers Follow

# Progressive number on relationship table

Hi everyone,

I would like to insert a progressive number (1, 2, 3 etc etc) for each row in this relation table.

How can I do.

Below is the code I currently use:

var Integrale = @All of 08VA - Integrale Data with nulls;
var Formatore = @All of 08VA - Formatore with nulls;
var UF = @All of 08VA - Unità Formativa with nulls;
var Data = @All of 08VA - Data with nulls;
var Valutazione = @All of Valutazione with nulls;
var Tipologia = @All of Tipologia di Prova with nulls
var linea = [];
for(var i = 0; i < Integrale.length;i++){
linea.push(Integrale[i] + " | " + Data[i] + " | " + UF[i] + " | " + Tipologia[i] + " | " + Valutazione[i] + " | " + Formatore[i]);
};

"ID | Data | UF | Tipologia | Valutazione | Formatore \n" +
"--- | --- | --- | --- | --- \n"+
linea.sort().join("\n")

regards

Claudio Calabrò

Hello Claudio,

whereever you want the progressive number put in: (i +1), e.g if you want it at the beginning

linea.push((i+1) + " " + Integrale[i] + " | " + Data[i] + " | " + UF[i] + " | " + Tipologia[i] + " | " + Valutazione[i] + " | " + Formatore[i]);

But cause you sort your array you can't put it that simple at the beginning (cause it would sort for the progressive number). You need to sort it before you add the progressive number, means you need a second for loop.

var linea = [];
for(var i = 0; i < Integrale.length;i++){
linea.push(Integrale[i] + " | " + Data[i] + " | " + UF[i] + " | " + Tipologia[i] + " | " + Valutazione[i] + " | " + Formatore[i]);
};
var linea = linea.sort();

var linea2= [];
for(var i = 0; i < linea.length;i++){
linea.push((i+1) + " " + linea[i]);
};

"ID | Data | UF | Tipologia | Valutazione | Formatore \n" +
"--- | --- | --- | --- | --- | --- \n"+
linea2.join("\n")

Rainer