- 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 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 08:25 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 09:00 AM
Hello
What did you give the name for script include? You will give the name of the script include is getIncrimentValue.

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