Make a new field auto numbered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 06:22 AM
Is it possible to have two fields in one table be auto numbered?
On Incident table, there is a number field which is auto numbered already.
Now I have created one more field (on same table)which also needs to be auto numbered on every update happened on the incident form.
Any help will be appreciated 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 06:31 AM
Is your requirement to have a second field which generates another unique number as INC0010000 or do you want to have a field which counts the number of updates done on the incident?
I don't think you can create a second field which uses the same mechanism as the number field, as the Business Rule getNextObjNumberPadded and Table Number Maintenance do not allow this. What you can do is to create your own field and write your own logic to get to the same result.
For counting the number of updates, I would look at the sys_mod_count field which is on the record already and stores the number of updates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 06:44 AM
Hi Ulrich,
Yes its my requirement, I have created my own field with type as Integer as i need only numeric value.
I tried with "getNextObjNumberPadded" which does not satisfy my requirement.
In case of Business Rule, which conditions I need to write.
e.g When incident is created, MessageNumber =1. If any update happened on that incident, then MessageNumber =2.
Another incident is created, then MessageNumber =3 like that.
this is my requirement.
If you can provide the code, it will be great help

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 07:52 AM
Sayali, I don't get the business logic for it, but for me it works with this on Insert/Update BR (before) on the incident table:
//https://community.servicenow.com/message/1290877?et=watches.email.thread#1290877
//whenever an incident is updated or inserted, we are increasing the Message Number field with the current max value
var gr = new GlideRecord('incident');
gr.addNotNullQuery('u_message_number');
gr.orderByDesc('u_message_number');
gr.setLimit(1);
gr.query();
var hasRecord = gr.next();
var messageNumber = gr.getValue('u_message_number');
if (hasRecord && typeof messageNumber == 'string') {
//get max and add 1
current.u_message_number = parseInt(messageNumber) + 1;
} else {
//this can only happen, if there was no previous value
current.u_message_number = 0;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2017 05:19 AM
sayalimore just to raise your attention to the script I created above ...