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

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

Got these Errors :

1. org.mozilla.javascript.EcmaError: "getIncrementValue" is not defined.
Caused by error in <refname> at line 1

==> 1: getIncrementValue();

 

2.org.mozilla.javascript.EcmaError: "getIncrementValue" is not defined.
Caused by error in <refname> at line 1

==> 1: getIncrementValue()

 

So, Changed default Value to javascript:gs.getIncrementValue()  from  

javascript:getIncrementValue();

Still, Value isn't getting Populated  and errors in Log too.

Hello

What did you give the name for script include? You will give the name of the script include is getIncrimentValue.

Hi,

It is never gs.getIncrementValue();

And, the name of Script Include must be same as the name of the function.

i.e. getIncrementValue

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

Thanks,

Archana