Sequential Number

Kumar38
Kilo Sage

Is there any Possibility of Using orderBy(Field Name )  to know highest number available and Increment the field Value by 1 for new records, or else any other approach ??

1 ACCEPTED SOLUTION

Archana Reddy2
Tera Guru

Hi,

Write a Script Include using the below code.

function getIncrementValue()
{
var gr = new GlideRecord('table_name');
gr.orderByDesc('field_name');
gr.setLimit(1);
gr.query();
if(gr.next())
{
return parseInt(gr.field_name) + 1;
}
}

 

Then, set the default value of that field to 

javascript:getIncrementValue();

Hope this helps.

Mark the answer as Correct/Helpful based on its impact.

Thanks,

Archana

View solution in original post

7 REPLIES 7

Working fine as expected , Is there a way I can Limit it to only e.x; 40 instead of 40.0. and Numbering should start from 40000 only 

Hi Krishna,

Limiting the result to Integer is possible and the below edited script helps you in that.

function getIncrementValue()
{
var gr = new GlideRecord('table_name');
gr.orderByDesc('field_name');
gr.setLimit(1);
gr.query();
if(gr.next())
{
var inc_value = parseFloat(gr.field_name++).toFixed(0);
return inc_value;
}
}

Numbering should start from 40000 : 

Not sure if I understood the question. Correct me if I am wrong.

If you are creating a new record in the table and want to default it to 40000, adding below script to the above one helps.

else
{
return 40000;
}

Hope this helps.

Mark the answer as Correct/Helpful based on its impact.

Thanks,

Archana

arielgritti
Mega Sage

Hello

Another approach is use "Number Maintenance" like this.

find_real_file.png

 

I hope my answer has been useful

Ariel

PS: Please mark my answer correct or helpful if I have helped you. Thanks