- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 06:02 AM
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 ??
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 07:03 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 09:48 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 11:01 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 07:09 AM